WCF Consumer Website: The Address property on ChannelFactory.Endpoint was null. The ChannelFactory's Endpoint must have a valid Address specified

…衆ロ難τιáo~ 提交于 2019-12-05 20:14:23
marc_s

Well, the error message really says it all:

Every binding must have at least one binding element that derives from TransportBindingElement.

The custom binding you defined only has a textMessageEncoding element - that's only half the story! As the error say - you must also add a transport element to it:

<customBinding>
   <binding name="WebHttpBinding_IService">
     <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
         messageVersion="Soap12" writeEncoding="utf-8">
         <readerQuotas maxDepth="32" maxStringContentLength="8192" 
                       maxArrayLength="16384" maxBytesPerRead="4096" 
                       maxNameTableCharCount="16384" />
     </textMessageEncoding>
     <httpTransport />
   </binding>
</customBinding>

See the new <httpTransport/> element? I'm never sure whether it needs to be first before the encoding, or after it - try it out, one of the two situations will work :-)

If you're hosting with SSL, you might need to use <httpsTransport /> instead.

Now, your custom binding should be complete to use.

Additionally, however - on your server side, you only have a "webHttpBinding" endpoint - but on the client, you are trying to connect to an endpoint that has "customBinding" enabled..... you need to make up your mind - those things need to match between server and client! On the server side, define the same endpoint you want to try to connect to from the client - otherwise it'll never work....

Also, since you're hosting in IIS, this setting of a base address is totally useless and won't do anything - just strip it out!

<service name="Service" behaviorConfiguration="ServiceBehavior">
    <host>
      <baseAddresses>
        <add baseAddress="https://myserverssl.com/Service.svc"/>
      </baseAddresses>
    </host>
...

The address of the service is always determine by server name (or IP), name of the virtual directory and the svc file inside that virtual directory - you cannot change that, you cannot modify that, you cannot influence that.

I'm pretty sure that Endpoint address shouldn't be a full address, it's relative to the Foobar.svc file (so, usually '/'). I haven't ever had to put the fully qualified URL into my web.config.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!