简体   繁体   English

如何嵌入app.config并对其Web服务端点进行硬编码?

[英]How to embed app.config and hard-code its web service endpoints?

I really don't know what endpoints an bindings do in app.config, but I know that I need a standalone .exe file and no more. 我真的不知道绑定在app.config中的作用是什么,但是我知道我只需要一个独立的.exe文件。 How can I embed that file in my exe, or how to hard-code the whole thing without using app.config. 我如何在我的exe文件中嵌入该文件,或者如何在不使用app.config的情况下对整个内容进行硬编码。 I have a small web service which returns a string value. 我有一个小型Web服务,该服务返回一个字符串值。 My app.config file reads like follows: 我的app.config文件内容如下:

` `

<configuration>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="APIServiceSoap" />
      </basicHttpBinding>
      <customBinding>
        <binding name="APIServiceSoap12">
          <textMessageEncoding messageVersion="Soap12" />
          <httpTransport />
        </binding>
      </customBinding>
    </bindings>
    <client>
      <endpoint address="http://www.example.com/APIService.asmx"
          binding="customBinding" bindingConfiguration="APIServiceSoap12"
          contract="MyWebAPI.APIServiceSoap" name="APIServiceSoap12" />
    </client>
  </system.serviceModel>
</configuration>`

And mu code begins like this: MyWebAPI.APIServiceSoapClient client = new MyWebAPI.APIServiceSoapClient(); mu代码是这样开始的: MyWebAPI.APIServiceSoapClient client = new MyWebAPI.APIServiceSoapClient(); Any kind of help would be appreciated. 任何帮助将不胜感激。 Thank you! 谢谢!

Because you are calling in to an ASMX Web Service with SOAP 1.2 and not a WCF one, things get a little more complicated, there are quite possibly several ways to do this, but the one I have used is: 因为您要使用SOAP 1.2而不是WCF来调用ASMX Web服务,所以事情变得有些复杂,有很多种方法可以做到这一点,但是我使用的是:

TextMessageEncodingBindingElement tmebe = new TextMessageEncodingBindingElement();
tmebe.MessageVersion = MessageVersion.Soap12;

TransportBindingElement tbe = new HttpTransportBindingElement();

CustomBinding binding = new CustomBinding(new BindingElement[] { tmebe, tbe });

EndpointAddress endpointAddress = new EndpointAddress("http://localhost/TestWebService/WebService1.asmx");
using (WebService1SoapClient client = new WebService1SoapClient(binding, endpointAddress))
{
    String result = client.HelloWorld();
    Debug.WriteLine(result);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM