Web Services 在控制台C#中使用Web服务

yzckvree  于 2022-11-15  发布在  C#
关注(0)|答案(1)|浏览(285)

我尝试在控制台应用程序中使用WebService,但总是出现此错误。
“无法加载”Giftcard.WebServiceSoap“协定得终结点配置节.找到该协定得多个配置.请按名称指示首选得终结点配置节.”
这是我的代码:

public class Program
    {
        static void Main(string[] args)
        {
            UserWebService.WebServiceSoapClient webServiceSoapClient = new UserWebService.WebServiceSoapClient();
            string id = "12345543";
            webServiceSoapClient.Login(id);
        }
    }

WEB配置

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
    </configSections>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
    </startup>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="WebServiceSoap">
                    <security mode="Transport" />
                </binding>
                <binding name="WebServiceSoap1" />
            </basicHttpBinding>
            <customBinding>
                <binding name="WebServiceSoap12">
                    <textMessageEncoding messageVersion="Soap12" />
                    <httpsTransport />
                </binding>
            </customBinding>
        </bindings>
        <client>
            <endpoint address="https://localhost:444/WebService.asmx" binding="basicHttpBinding"
                bindingConfiguration="WebServiceSoap" contract="UserWebService.WebServiceSoap"
                name="WebServiceSoap" />
            <endpoint address="https://localhost:444/WebService.asmx" binding="customBinding"
                bindingConfiguration="WebServiceSoap12" contract="UserWebService.WebServiceSoap"
                name="WebServiceSoap12" />
        </client>
    </system.serviceModel>
</configuration>

我已经从此处添加了对Web服务的引用:

eni9jsuy

eni9jsuy1#

添加要在UserWebService.WebServiceSoapClient(“WebServiceSoap”)的构造函数中使用的bindingConfiguration="WebServiceSoap”名称。

public class Program
    {
        static void Main(string[] args)
        {
            UserWebService.WebServiceSoapClient webServiceSoapClient = new UserWebService.WebServiceSoapClient("WebServiceSoap");
            string id = "12345543";
            webServiceSoapClient.Login(id);
        }
    }

相关问题