假设:
我正在使用名为DemoWCF的WCF应用程序,其中我有一个名为Calculator的简单wcf服务。
该应用程序的目的显然是一个演示,WCF服务必须将两个数字作为参数并将它们相加。
服务类:
public class Calculator : ICalculator
{
public int Sum(int firstValue, int secondValue)
{
return firstValue + secondValue;
}
}
服务合同:
[ServiceContract(Namespace="http://ROCKET/Calculator")]
public interface ICalculator
{
[OperationContract]
int Sum(int firstValue, int secondValue);
}
Web.config,服务模型配置:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="wsHttpsBinding">
<security mode="Transport">
<transport clientCredentialType="None"></transport>
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service name="DemoWCF.Services.ServiceClasses.Calculator">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsHttpsBinding" contract="DemoWCF.Services.ServiceContracts.ICalculator" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<serviceMetadata httpsGetEnabled="true" httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
当我在IIS上部署WCF应用程序并尝试在SOAP UI或ASP.NET MVC应用程序中使用WCF服务时,一切正常。
目标:
当我在SOAP UI中使用WCF服务时,我注意到从Web服务的wsdl自动生成绑定&#34; WSHttpBinding_ICalculator&#34;。
当我在ASP.NET MVC应用程序中使用WCF服务时,我注意到Web服务的wsdl自动生成了服务模型,正好:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_ICalculator">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://rocket/ServiceClasses/Calculator.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ICalculator" contract="Calculator.ICalculator" name="WSHttpBinding_ICalculator" />
</client>
</system.serviceModel>
我想要做的是重命名WCF服务的服务名称和绑定名称。
可以省略这种WCF生成绑定名称的行为,其格式为:&#34; BindingType_IServiceInterface&#34; ?
如果我想在&#34;计算器&#34;中重命名我的服务名称和绑定名称,我该怎么办? ?