Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 重命名WCF服务名称&;绑定名_C#_Web Services_Wcf - Fatal编程技术网

C# 重命名WCF服务名称&;绑定名

C# 重命名WCF服务名称&;绑定名,c#,web-services,wcf,C#,Web Services,Wcf,假设: 我正在使用一个名为DemoWCF的WCF应用程序,其中有一个名为Calculator的简单WCF服务 应用程序的目的显然是一个演示,WCF服务必须将两个数字作为参数并求和 服务类别: 服务合同: Web.config,服务模型配置: 当我在IIS上部署WCF应用程序,并尝试在SOAP UI或ASP.NET MVC应用程序中使用WCF服务时,一切正常 目标: 当我在soapui中使用WCF服务时,我注意到web服务的wsdl会自动生成绑定“WSHttpBinding_ICalculat

假设:
我正在使用一个名为DemoWCF的WCF应用程序,其中有一个名为Calculator的简单WCF服务

应用程序的目的显然是一个演示,WCF服务必须将两个数字作为参数并求和

服务类别:

服务合同:

Web.config,服务模型配置:


当我在IIS上部署WCF应用程序,并尝试在SOAP UI或ASP.NET MVC应用程序中使用WCF服务时,一切正常

目标:
当我在soapui中使用WCF服务时,我注意到web服务的wsdl会自动生成绑定“WSHttpBinding_ICalculator”

当我在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行为,其格式为:“BindingType_IServiceInterface”


如果我想在“Calculator”中重命名我的服务名和绑定名,我必须做什么?

为什么要重命名它们?是否有某种功能或业务原因导致了这种情况?如果没有,我建议保持原样,因为它可能需要付出的努力(如果可以做到的话)似乎远远超过了它的好处。假设这只是我的一位客户提出的美学要求。我们都很想知道,是否可以省略这个WCF行为,使用不同于服务类的名称来调用服务名和绑定名。显然,请求的一部分是找到一种简单的方法,既不破坏web服务,也不重写太多的代码行。
[ServiceContract(Namespace="http://ROCKET/Calculator")]
public interface ICalculator
{
    [OperationContract]
    int Sum(int firstValue, int secondValue);
}
<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>
<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>