我已经创建了 wcf 应用程序:这个合同:
namespace WcfServiceLibrary1 { [ServiceContract] public interface IService1 { [OperationContract] string GetData(int value); } }
这是服务:
namespace WcfServiceLibrary1 { public class Service1 : IService1 { public string GetData(int value) { return string.Format("You entered: {0}", value); } } }
这是 App.config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpRuntime maxRequestLength="2097151"
useFullyQualifiedRedirectUrl="true"
executionTimeout="144000" />
</system.web>
<system.serviceModel>
<!--<bindings>
<basicHttpBinding>
<binding name="FileTransferServicesBinding" transferMode="Streamed" messageEncoding="Mtom" maxReceivedMessageSize="2000000">
</binding>
</basicHttpBinding>
</bindings>-->
<bindings>
<wsDualHttpBinding>
<binding name="WSDualHttpBinding_IChatService" closeTimeout="00:03:00" openTimeout="00:03:00" receiveTimeout="00:10:00"
sendTimeout="00:03:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="104857600" maxReceivedMessageSize="104857600" messageEncoding="Mtom" textEncoding="utf-8" useDefaultWebProxy="true">
<readerQuotas maxDepth="104857600" maxStringContentLength="104857600" maxArrayLength="104857600" maxBytesPerRead="104857600" maxNameTableCharCount="104857600"/>
<reliableSession ordered="true" inactivityTimeout="00:10:00"/>
<security mode="None">
<message clientCredentialType="None" negotiateServiceCredential="false" algorithmSuite="Default"/>
</security>
</binding>
</wsDualHttpBinding>
</bindings>
<services>
<!--<service behaviorConfiguration="MyServiceTypeBehaviors" name="FileService.FileTransferService">
<endpoint address="mex" binding="basicHttpBinding" bindingConfiguration="FileTransferServicesBinding" contract="FileService.IFileTransferService"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/FileTranfer"/>
</baseAddresses>
</host>
</service>-->
<service behaviorConfiguration="MyServiceTypeBehaviors" name="WcfServiceLibrary1.Service1">
<endpoint address="mex" binding="wsDualHttpBinding" bindingConfiguration="WSDualHttpBinding_IChatService" contract="WcfServiceLibrary1.IService1"/>
<host>
<baseAddresses>
<add baseAddress="http://117.5.36.172:23000/FileTranfer"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceTypeBehaviors">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
在地址添加服务引用后:“http://117.5.36.172:23000/FileTranfer”我运行服务正常。创建后:
ServiceReference1.Service1Client 客户端 = new ServiceReference1.Service1Client();
Console.WriteLine(client.State); ====> return Created Console.WriteLine(client.GetData(5)); ==>Not return value, seems