c# - 如何嵌入 app.config 并对其 Web 服务端点进行硬编码?
问题描述
我真的不知道绑定在 app.config 中做什么端点,但我知道我需要一个独立的 .exe 文件,仅此而已。如何在我的 exe 中嵌入该文件,或者如何在不使用 app.config 的情况下对整个内容进行硬编码。我有一个返回字符串值的小型 Web 服务。我的 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>`
mu 代码的开头是这样的:
MyWebAPI.APIServiceSoapClient client = new MyWebAPI.APIServiceSoapClient();
任何形式的帮助都将不胜感激。谢谢!
解决方案
因为您调用的是使用 WCF 而不是 WCF 的ASMX
Web 服务SOAP 1.2
,所以事情变得有点复杂,很可能有几种方法可以做到这一点,但我使用的是:
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);
}
推荐阅读
- javascript - 有没有办法使用 Office.js 在 powerpoint 演示文稿中突出显示文本
- ios - CocoaPods 'framework not found FBLPromises' 同时减少 podfile 大小
- maven - java.lang.NoClassDefFoundError: io/cucumber/core/options/CucumberOptionsAnnotationParser$OptionsProvider 抛出 maven serenity-cucumber 项目
- powerbi - 按列值过滤用户
- python - 从类方法生成烧瓶路线
- java - Dto - 实体映射最佳实践
- mongodb - Mongo-Connector 不向 Elasticsearch 发送数据
- .net - 为什么当我运行 `dotnet dev-certs -c` 时没有找到证书,但是当我运行 `dotnet dev-certs --trust` 时它说已经有一个有效的证书
- macos - 命令“gcc”在 MacOS 中以退出状态 1 失败
- d3.js - 如何在 dc.js 饼图切片中添加图标而不是文本