<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>WCF</title>
        <link>http://agilior.pt/blogs/pedro.rainho/category/40.aspx</link>
        <description>WCF</description>
        <language>pt-PT</language>
        <copyright>Pedro Rainho</copyright>
        <managingEditor>pedro.rainho@agilior.pt</managingEditor>
        <generator>Subtext Version 1.9.0.27</generator>
        <item>
            <title>WCF and net.pipe exception</title>
            <link>http://agilior.pt/blogs/pedro.rainho/archive/2009/04/22/7597.aspx</link>
            <description>&lt;p&gt;Today I came across an odd problem related with WCF and net.pipe binding.&lt;/p&gt;  &lt;p&gt;If I expose one pipe on address “net.pipe://&lt;strong&gt;aaa&lt;/strong&gt;/service/endpoint” and another on address “net.pipe://&lt;strong&gt;bbb&lt;/strong&gt;/service/endpoint” I got this exception &lt;/p&gt;  &lt;p&gt;“Cannot listen on pipe name net.pipe://bbb/service/endpoint because another pipe endpoint is already listening on that name. “&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;I found this very strange.&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;The logical explanation I have is this: &lt;/p&gt;  &lt;p&gt;- net.pipe:// represents the transport protocol.&lt;/p&gt;  &lt;p&gt;- aaa or bbb represents the machine or domain. Since net pipes are local I think aaa and bbb are ignored.&lt;/p&gt;  &lt;p&gt;- service/endpoint represents the absolute path where the service is exposed.&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;So the solution to solve this problem was this:&lt;/p&gt;  &lt;p&gt;net.pipe://pipe/&lt;strong&gt;aaa&lt;/strong&gt;/service/endpoint&lt;/p&gt;  &lt;p&gt;net.pipe://pipe/&lt;strong&gt;bbb&lt;/strong&gt;/service/endpoint&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;Now the absolute path /aaa/service/endpoint and /bbb/service/endpoint are different and no exception is generated&lt;/p&gt;&lt;img src="http://agilior.pt/blogs/pedro.rainho/aggbug/7597.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Pedro Rainho</dc:creator>
            <guid>http://agilior.pt/blogs/pedro.rainho/archive/2009/04/22/7597.aspx</guid>
            <pubDate>Wed, 22 Apr 2009 13:59:24 GMT</pubDate>
            <wfw:comment>http://agilior.pt/blogs/pedro.rainho/comments/7597.aspx</wfw:comment>
            <comments>http://agilior.pt/blogs/pedro.rainho/archive/2009/04/22/7597.aspx#feedback</comments>
            <wfw:commentRss>http://agilior.pt/blogs/pedro.rainho/comments/commentRss/7597.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Remove tempuri from WCF service</title>
            <link>http://agilior.pt/blogs/pedro.rainho/archive/2009/01/12/6661.aspx</link>
            <description>&lt;p&gt;If any one ever want was remove all &lt;a href="http://tempuri.org"&gt;http://tempuri.org&lt;/a&gt; namespaces from wcf service I really recommend all to check this two posts in &lt;a href="http://www.pluralsight.com/community/blogs/kirillg/archive/2006/06/18/28380.aspx" title="http://www.pluralsight.com/community/blogs/kirillg/archive/2006/06/18/28380.aspx"&gt;http://www.pluralsight.com/community/blogs/kirillg/archive/2006/06/18/28380.aspx&lt;/a&gt; and &lt;a href="http://cglessner.blogspot.com/2008/07/kill-tempuri-in-wcf-services.html" title="http://cglessner.blogspot.com/2008/07/kill-tempuri-in-wcf-services.html"&gt;http://cglessner.blogspot.com/2008/07/kill-tempuri-in-wcf-services.html&lt;/a&gt;. Helped me solve my problems.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;One other thing I found when I was removing the &lt;a href="http://tempuri.org"&gt;http://tempuri.org&lt;/a&gt; namespaces.&lt;/p&gt;
&lt;p&gt;If I want this:&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&amp;lt;wsdl:definitions name="MyWCFService" &lt;strong&gt;targetNamespace="http://MyCompany/mywcfservice/"&lt;/strong&gt;&amp;gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;I need to do this:&lt;/p&gt;
&lt;p&gt;[ServiceBehavior(Namespace="http://MyCompany/mywcfservice/")]&lt;/p&gt;
&lt;p&gt;public class MyWCFService : IMyWCFServiceContract&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Or do this:&lt;/p&gt;
&lt;p&gt;public class MyWCFService : IMyWCFServiceContract&lt;/p&gt;
&lt;p&gt;and inside MyServiceHost do:&lt;/p&gt;
&lt;p&gt;this.Description.Namespace = “http://MyCompany/mywcfservice/”;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;don’t try this because it will not remove tempuri:&lt;/p&gt;
&lt;p&gt;ServiceBehaviorAttribute serviceBehaviorAtribute = this.Description.Behaviors.Find&amp;lt;ServiceBehaviorAttribute&amp;gt;();&lt;/p&gt;
&lt;p&gt;serviceBehaviorAtribute.Namespace = “http://MyCompany/mywcfservice/”;&lt;/p&gt;
&lt;p&gt;This was my first choice until I realize my mistake.&lt;/p&gt;&lt;img src="http://agilior.pt/blogs/pedro.rainho/aggbug/6661.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Pedro Rainho</dc:creator>
            <guid>http://agilior.pt/blogs/pedro.rainho/archive/2009/01/12/6661.aspx</guid>
            <pubDate>Mon, 12 Jan 2009 14:30:43 GMT</pubDate>
            <wfw:comment>http://agilior.pt/blogs/pedro.rainho/comments/6661.aspx</wfw:comment>
            <comments>http://agilior.pt/blogs/pedro.rainho/archive/2009/01/12/6661.aspx#feedback</comments>
            <wfw:commentRss>http://agilior.pt/blogs/pedro.rainho/comments/commentRss/6661.aspx</wfw:commentRss>
        </item>
        <item>
            <title>WCF and HTTP GET</title>
            <link>http://agilior.pt/blogs/pedro.rainho/archive/2008/04/16/4336.aspx</link>
            <description>&lt;p&gt;Lets imagine that you need to invoke a url "http://localhost/webapp/run.aspx" and the result of calling this url is XML. And lets imagine that you need to call that url and pass some parameters via HTTP GET. The question is how can I do that?&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;I can use &lt;/p&gt;
&lt;pre&gt;HttpWebRequest &lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Or I can use WCF.&lt;/p&gt;
&lt;p&gt;The First thing I need to do is define the service contract. So lets create the service contract&lt;/p&gt;
&lt;pre class="code"&gt;[&lt;span style="color: rgb(43, 145, 175);"&gt;ServiceContract&lt;/span&gt;]&lt;br /&gt;&lt;span style="color: blue;"&gt;public interface &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;IHTTPGetCall&lt;br /&gt;&lt;/span&gt;{&lt;br /&gt;    [&lt;span style="color: rgb(43, 145, 175);"&gt;OperationContract&lt;/span&gt;(Action = &lt;span style="color: rgb(163, 21, 21);"&gt;"*"&lt;/span&gt;)]&lt;br /&gt;    &lt;span style="color: rgb(43, 145, 175);"&gt;Message &lt;/span&gt;Send(&lt;span style="color: rgb(43, 145, 175);"&gt;Message &lt;/span&gt;request);&lt;br /&gt;}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Note the operation contract need to receive a Message and return a Message&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;The second thing I need to worry is, how can I create  a Message Object to enable me call using HTTP GET&lt;/p&gt;
&lt;p&gt;I'm goind to use HttpRequestMessageProperty&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;In this type I have to define:&lt;/p&gt;
&lt;p&gt;SuppressEntityBody = false&lt;/p&gt;
&lt;p&gt;Method = "GET"&lt;/p&gt;
&lt;p&gt;and QueryString = Some query string&lt;/p&gt;
&lt;p&gt;So lets create the HttpRequestMessageProperty&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;Message &lt;/span&gt;BuildMessage()     &lt;br /&gt;
{     &lt;br /&gt;
    &lt;span style="color: rgb(43, 145, 175);"&gt;Message&lt;/span&gt;messageToSend = &lt;span style="color: blue;"&gt;null&lt;/span&gt;;     &lt;br /&gt;
    &lt;span style="color: rgb(43, 145, 175);"&gt;HttpRequestMessageProperty &lt;/span&gt;reqProps = &lt;span style="color: blue;"&gt;new &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;HttpRequestMessageProperty&lt;/span&gt;();     &lt;br /&gt;
    reqProps.SuppressEntityBody = &lt;span style="color: blue;"&gt;false&lt;/span&gt;;     &lt;br /&gt;
    reqProps.Method = &lt;span style="color: rgb(163, 21, 21);"&gt;"GET"&lt;/span&gt;;     &lt;br /&gt;
    reqProps.QueryString = &lt;span style="color: rgb(163, 21, 21);"&gt;"SID=1234567890&amp;amp;x=1"&lt;/span&gt;;     &lt;br /&gt;
&lt;br /&gt;
    &lt;span style="color: blue;"&gt;try      &lt;br /&gt;
   &lt;/span&gt;{     &lt;br /&gt;
        messageToSend = &lt;span style="color: rgb(43, 145, 175);"&gt;Message&lt;/span&gt;.CreateMessage(&lt;span style="color: rgb(43, 145, 175);"&gt;MessageVersion&lt;/span&gt;.None, &lt;span style="color: blue;"&gt;string&lt;/span&gt;.Empty);     &lt;br /&gt;
    }     &lt;br /&gt;
    &lt;span style="color: blue;"&gt;catch&lt;/span&gt;(&lt;span style="color: rgb(43, 145, 175);"&gt;Exception&lt;/span&gt;e)     &lt;br /&gt;
    {     &lt;br /&gt;
        &lt;span style="color: rgb(43, 145, 175);"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: rgb(163, 21, 21);"&gt;"got exception when sending message: "&lt;/span&gt;+ e.ToString());     &lt;br /&gt;
    }     &lt;br /&gt;
&lt;br /&gt;
    messageToSend.Properties[&lt;span style="color: rgb(43, 145, 175);"&gt;HttpRequestMessageProperty&lt;/span&gt;.Name] = reqProps;     &lt;br /&gt;
    &lt;span style="color: blue;"&gt;return&lt;/span&gt;messageToSend;     &lt;br /&gt;
}&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Note that in previous method I create a HttpRequestMessageProperty and after that I create my message&lt;/p&gt;
&lt;p&gt;We are half done.&lt;/p&gt;
&lt;p&gt;Next...&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;I need to create My channel factory, my binding, my enconder, my transport, my endpoint and make my call.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue;"&gt;public static void &lt;/span&gt;Main()&lt;br /&gt;{&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;pre class="code"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;ChannelFactory&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(43, 145, 175);"&gt;IHTTPGetCall&lt;/span&gt;&amp;gt; channelFactory;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;CustomBinding &lt;/span&gt;poxBinding = &lt;span style="color: blue;"&gt;new &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;CustomBinding&lt;/span&gt;();&lt;br /&gt;poxBinding.SendTimeout = &lt;span style="color: blue;"&gt;new &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;TimeSpan&lt;/span&gt;(0, 0, 0, 0, 50000);&lt;br /&gt;poxBinding.ReceiveTimeout = &lt;span style="color: blue;"&gt;new &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;TimeSpan&lt;/span&gt;(0, 0, 0, 0, 50000);&lt;br /&gt;&lt;br /&gt;poxBinding.OpenTimeout = &lt;span style="color: blue;"&gt;new &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;TimeSpan&lt;/span&gt;(0, 0, 0, 0, 50000);&lt;br /&gt;poxBinding.CloseTimeout = &lt;span style="color: blue;"&gt;new &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;TimeSpan&lt;/span&gt;(0, 0, 0, 0, 50000);&lt;br /&gt;&lt;br /&gt;&lt;span style="color: green;"&gt;// Encoder&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;TextMessageEncodingBindingElement &lt;/span&gt;encoder =&lt;br /&gt;    &lt;span style="color: blue;"&gt;new &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;TextMessageEncodingBindingElement&lt;/span&gt;();&lt;br /&gt;encoder.MessageVersion = &lt;span style="color: rgb(43, 145, 175);"&gt;MessageVersion&lt;/span&gt;.None;&lt;br /&gt;&lt;br /&gt;poxBinding.Elements.Add(encoder);&lt;br /&gt;&lt;br /&gt;&lt;span style="color: green;"&gt;// Transport&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;HttpTransportBindingElement &lt;/span&gt;transport = &lt;span style="color: blue;"&gt;new &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;HttpTransportBindingElement&lt;/span&gt;();&lt;br /&gt;poxBinding.Elements.Add(transport);&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;EndpointAddress &lt;/span&gt;endpointAddress = &lt;span style="color: blue;"&gt;new &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;EndpointAddress&lt;/span&gt;(&lt;span style="color: rgb(163, 21, 21);"&gt;"http://localhost/webapp/run.aspx"&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt;channelFactory = &lt;span style="color: blue;"&gt;new &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;ChannelFactory&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(43, 145, 175);"&gt;IHTTPGetCall&lt;/span&gt;&amp;gt;(poxBinding, endpointAddress);&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;IHTTPGetCall &lt;/span&gt;mycall= channelFactory.CreateChannel();&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;Message &lt;/span&gt;SendMessage = BuildMessage();&lt;br /&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;Message &lt;/span&gt;messageMyCall = mycall.Send(SendMessage);&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;StringBuilder &lt;/span&gt;messageContent = &lt;span style="color: blue;"&gt;new &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;StringBuilder&lt;/span&gt;();&lt;br /&gt;messageMyCall.WriteMessage(&lt;span style="color: blue;"&gt;new &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;XmlTextWriter&lt;/span&gt;(&lt;span style="color: blue;"&gt;new &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;StringWriter&lt;/span&gt;(messageContent)));&lt;br /&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;Console&lt;/span&gt;.WriteLine( messageContent.ToString());&lt;/pre&gt;
&lt;pre class="code"&gt;}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Note that in the Endpoint address I'm defining the location and in the HttpRequestMessageProperty I'm defining the querystring&lt;/p&gt;&lt;img src="http://agilior.pt/blogs/pedro.rainho/aggbug/4336.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Pedro Rainho</dc:creator>
            <guid>http://agilior.pt/blogs/pedro.rainho/archive/2008/04/16/4336.aspx</guid>
            <pubDate>Wed, 16 Apr 2008 16:00:19 GMT</pubDate>
            <wfw:comment>http://agilior.pt/blogs/pedro.rainho/comments/4336.aspx</wfw:comment>
            <comments>http://agilior.pt/blogs/pedro.rainho/archive/2008/04/16/4336.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://agilior.pt/blogs/pedro.rainho/comments/commentRss/4336.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>