Failed to invoke the service. Possible causes: The

2019-09-07 00:23发布

问题:

I have my service configured as below:

<system.serviceModel>
    <services>
      <service name="WcfService1.Service1" behaviorConfiguration="MyServiceTypeBehaviors">
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://127.0.0.1:808/service" />
          </baseAddresses>
        </host>
        <endpoint address="net.tcp://127.0.0.1:808/service/"
                  binding="netTcpBinding"
                  contract="WcfService1.IService1"/>
        <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"   />

      </service>
    </services>
    <protocolMapping>
      <add scheme="net.tcp" binding="netTcpBinding"/>
    </protocolMapping>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MyServiceTypeBehaviors">
          <serviceMetadata httpGetEnabled="true"/>
        </behavior>
      </serviceBehaviors>
    <endpointBehaviors>
      <behavior name="MyEndpointBehaviour">
        <webHttp/>
      </behavior>
    </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

and the client as:

 <system.serviceModel>
        <bindings>
            <netTcpBinding>
                <binding name="NetTcpBinding_IService1" sendTimeout="00:05:00" />
            </netTcpBinding>
        </bindings>
        <client>
            <endpoint address="net.tcp://127.0.0.1/service/" binding="netTcpBinding"
                bindingConfiguration="NetTcpBinding_IService1" contract="IService1"
                name="NetTcpBinding_IService1">
                <identity>
                    <servicePrincipalName value="host/MachineName" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>

When using WCFTestClient or SVCutil, I am able to discover and access the servie and generate proxy or stubs.

But when I want to invoke any of the methods getting following error:

Failed to invoke the service. Possible causes: The service is offline or inaccessible; the client-side configuration does not match the proxy; the existing proxy is invalid. Refer to the stack trace for more detail. You can try to recover by starting a new proxy, restoring to default configuration, or refreshing the service.

The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:04:59.9980468'.

回答1:

Maybe not the answer you are looking for, but for development on the local machine I always use an HTTP endpoint. I find Net.TCP will only play nice when it is hosted on a server in IIS.

It is easy enough to add the NET.TCP endpoints once you deploy to an IIS server. Note: that the base address no longer has any affect as that is set in IIS. To test the new endpoints it is best to start by opening the service in a browser while remoted into the server, that way you get the best error messages.

If i understand correctly you are trying to select the endpoint when creating the service reference? Thats now how it works. If you create your service reference using 127.0.0.1/service/Service1.svc

You should see in your config file something like the following. (When I create my service endpoints I always name them with the protocol as a suffix.

        <endpoint address="http://servername:8090/servername/servername.svc/Business"
              binding="basicHttpBinding" bindingConfiguration="BusinessHTTP"
              contract="servername.IService" name="BusinessHTTP" />
       <endpoint address="net.tcp://servername:8030/Service/Service.svc/Business"
              binding="netTcpBinding" bindingConfiguration="BusinessTCP"
              contract="servername.IService" name="BusinessTCP" />

then in your code you can choose which endpoint to use.

Dim svc as New SeviceReferenceName.BusinessClient("BusinessTCP")"


回答2:

Set the following value inside the endpoint block

<identity>
   <dns value ="localhost"/>
</identity>


回答3:

NetTcp binding is secured by default.In the security authentication process between client and service,WCF ensures that the identity of service matches the values of this element. Therefore service need to be configured with :

<identity>
   <dns value ="localhost"/>
</identity>


回答4:

I have faced the same issue. It was the issue of port address of EndpointAddress. In Visual studio port address of your file (e.g. Service1.svc) and port address of your wcf project must be the same which you gives into EndpointAddress. Let me describe you this solution in detail which worked for me.

There are two steps to check the port addresses.

  1. In your WCF Project right click to your Service file (e.g. Service1.svc) -> than select View in browser now in your browser you have url like http://localhost:61122/Service1.svc so now note down your port address as a 61122

  2. Right click your wcf project -> than select Properties -> go to the Web Tab -> Now in Servers section -> select Use Visual Studio Development Server -> select Specific Port and give the port address which we have earlier find from our Service1.svc service. That is (61122).

Earlier, I had a different port address. After specifying the port address properly, which I got from the first step, EndpointAddress 61122, my problem was solved.

I hope this might be solved your issue.



标签: c# .net wcf rest