簡體   English   中英

設置 NetTcpBinding

[英]Setting Up NetTcpBinding

設置 NetTcpBinding。 嘗試從服務器獲取數據時出現錯誤。 使用 WCFTestClient 進行了測試。

我是 WCF 的新手。 我可能錯過了 IIS 設置或在綁定中犯了錯誤。 請幫助我們理解問題。

The message with To
'net.tcp://wssekbdev-5-loc.wss.loc/_layouts/WSS/WSSC.V4.DMS.TestWCF.WcfService1/Service3.svc' cannot be processed at the receiver, due to an AddressFilter mismatch at the EndpointDispatcher.  Check that the sender and receiver's EndpointAddresses agree.
      Server stack trace:     at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)    at
      System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)    at
 System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)    at
 System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)    at
 System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
 
 Exception rethrown at [0]:     at
 System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessagereqMsg, IMessage retMsg)    at
 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)    at
 IServiceContract.Login(String username)    at
 ServiceContractClient.Login(String username)

在此處輸入圖片說明

代碼服務器

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
public class ServiceTest : IServiceContract
{
    public string Login(string username)
    {
        return $"ok:{username}";
    }

    public void Message(string message, string userFrom)
    {
         
    }
}

[ServiceContract()]
public interface IServiceContract
{
    [OperationContract]
    string Login(string username);

    [OperationContract(IsOneWay = true)]
    void Message(string message, string userFrom);
}

配置

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <directoryBrowse enabled="true" />
  </system.webServer> 
  <system.web> 
    <httpRuntime />
    <customErrors mode="RemoteOnly" />
    <compilation targetFramework="4.5" />
        <identity impersonate="false" />
  </system.web>
  <system.serviceModel>
    
    <bindings> 
      <netTcpBinding>
        <binding name="TestBinding" sendTimeout="00:01:00">
          <reliableSession ordered="true" enabled="false" />
          <security mode="None" /> 
        </binding>
      </netTcpBinding>  
    </bindings>
    <services>
 
      <service name="WSSC.V4.DMS.TestWCF.WcfService1.ServiceTest">
        <endpoint binding="netTcpBinding" contract="WSSC.V4.DMS.TestWCF.WcfService1.IServiceContract"
                  bindingConfiguration="TestBinding"
                  />
 
        <endpoint binding="wsHttpBinding" contract="WSSC.V4.DMS.TestWCF.WcfService1.IServiceContract"/>
        
        <endpoint address = "mex" binding = "mexTcpBinding" contract = "IMetadataExchange" /> 
      </service>


    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior > 
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

在此處輸入圖片說明 在此處輸入圖片說明

如果您的服務在 Visual Studio Development Server 中運行,則無法配置 netTcpBinding。 原因是 Visual Studio Development Server 僅支持 HTTP。

您需要更改項目屬性,如下所示:

在此處輸入圖片說明

你也可以告訴我你調用服務時發生了什么錯誤,我可以幫你解決。

我根據你提供的信息創建了一個部署在IIS中的WCF項目,但是沒有發現任何錯誤。

確保以下服務正在運行:

在此處輸入圖片說明

如果問題仍然存在,請隨時告訴我。

項目設置已正確指定。 我重新啟動了 IIS,重新啟動了服務,它工作正常。 非常感謝你的幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM