1. wcf相关项目名称Service1.svc、IDataChangeTest.cs和DataChangeTest.cs(下面的专业名称可能不太准确)。
Service1.svc宿主,里面只关联接口的空间
IdataChangeTest.cs里边是接口,如下:
……
/// <summary>/// 通过特定表的特定字段取得Datatable
/// </summary>
/// <param name="tableName">表名</param>
/// <param name="fieldname">字段名</param>
/// <param name="fieldval">对应的值</param>
/// <param name="accWord">验证编码</param>
/// <returns></returns>
[OperationContract]
DataTable GetTableDataByField(string tableName, string fieldname, string fieldval, string accWord);
……
DataChangeTest.cs为实际的方法,如下:
……
2. 下面是wcf的config设置:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<!-- 2147483647最大字节数,这个是int32的最大字节数,大小是2047M,肯定能适合正常的数据传输。估计不用全部设置成这么大都够用。-->
<binding name="NewBinding0" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="metadataBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<!—metadataBehavior对应的是“<behavior name="metadataBehavior">”的name,名称无所谓,只要对应就好。Services.DataChangeTest是调用方法DataChangeTest.cs窗体对应的空间名称和窗体类名称;Contracts.IdataChangeTest是调用接口IdataChangeTest.cs窗体对应的空间名称和窗体类名称;NewBinding0对应上面“<binding name="”的name-->
<services>
<service behaviorConfiguration="metadataBehavior" name="Services.DataChangeTest">
<endpoint binding="wsHttpBinding" bindingConfiguration="NewBinding0" contract="Contracts.IDataChangeTest"/>
</service>
<!—下面两处红色的部分会影响发布之后scf的调用,如果没有,发布之后无法引用。-->
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<system.web>
<compilation debug="true"/>
</system.web>
</configuration>
3.下面是app.config里面的设置,这个基本上是引用Service Reference时自动产生的,我只是把对应的size改的大了些。
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IDataChangeTest" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<!—http://192.168.254.64:82/Service1.svc是发布之后的地址;
WSHttpBinding_IDataChangeTest这个是上面bing的name,这个可能是由ServiceReference1.IdataChangeTest的来的,估计可以随便写,个人猜测;
ServiceReference1.IdataChangeTest这个是对应引用的ServiceReference1,双击他,左面会显示出来,如下面的图片-->
<client>
<endpoint address="http://192.168.254.65:82/Service1.svc" binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IDataChangeTest" contract="ServiceReference1.IDataChangeTest"
name="WSHttpBinding_IDataChangeTest">
<identity>
<servicePrincipalName value="host/Hqyr-PC" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
上面只是解决的具体方法,相信我说的已经很详细了。之前查过很长时间,一直未找到解决的方案。现在解决,我在想不是之前查到的那些文章没有说明白,应该是自己没有静下心来好好的看吧。很多时候遇到问题,我们总是在想:找到个一下子能解决的方法,却忽略了很多细节。也许我更关注的是结果,而不是过程。虽然受时间的压迫这个因素会让我们倾向于这样想!我想细节能影响一件事情的成败,更决定了一个人的层次。
在努力一点,细心一点,你会更成功!跟自己说,跟像我一样 “急功近利 ”的人说。