.net 是否将此app.config xml转换为代码?(WCF)
我需要将下面的app.config部分转换为代码。我已经看到了几个例子,但仍然不能完全让它发挥作用。有人能帮忙吗.net 是否将此app.config xml转换为代码?(WCF),.net,wcf,app-config,.net,Wcf,App Config,我需要将下面的app.config部分转换为代码。我已经看到了几个例子,但仍然不能完全让它发挥作用。有人能帮忙吗 <system.serviceModel> <bindings> <basicHttpBinding> <binding name="MyService" closeTimeout="00:01:00" openTimeout="00:0
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="MyService"
closeTimeout="00:01:00"
openTimeout="00:01:00"
receiveTimeout="00:10:00"
sendTimeout="00:01:00"
allowCookies="false"
bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536"
maxBufferPoolSize="524288"
maxReceivedMessageSize="65536"
messageEncoding="Text"
textEncoding="utf-8"
transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32"
maxStringContentLength="8192"
maxArrayLength="16384"
maxBytesPerRead="4096"
maxNameTableCharCount="16384" />
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="None"
proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName"
algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://server.com/service/MyService.asmx"
binding="basicHttpBinding" bindingConfiguration="MyService"
contract="MyService.MyServiceInterface"
name="MyService" />
</client>
</system.serviceModel>
我的使用案例是,我正在编写一个dll,该dll将被其他非.net应用程序使用,从今往后,我就没有好地方放置app.config了
谢谢 您可以使用类似这样的东西(看起来非常标准的basicHttpBinding):
BasicHttpBinding=new BasicHttpBinding();
Uri endpointAddress=新Uri(“https://server.com/service/MyService.asmx");
ChannelFactory=新的ChannelFactory(绑定,端点地址);
MyService.MyServiceInterface proxy=factory.CreateChannel();
只要您有一个包含契约(“MyService.MyServiceInterface”)的DLL可用,并且您可以在客户端中引用它,这种方法就可以工作
如果您在服务端需要它,您将不得不使用一些不同的类等,但基本原理是相同的(创建绑定,创建一个或多个端点地址,绑定它们)
马克
PS:对不起,我刚刚注意到您使用了https://地址-这可能需要在代码中进行一些额外的安全配置。谢谢您,marc_s,您引导我的方向是正确的 对于任何感兴趣的人,以下是使其与SSL一起工作的代码:
BasicHttpBinding binding = new BasicHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.TransportWithMessageCredential;
Uri endpointAddress = new Uri("https://server.com/Service.asmx");
ChannelFactory<MyService.MyServiceInterface> factory = new ChannelFactory<MyService.MyServiceInterface>(binding, endpointAddress.ToString());
factory.Credentials.UserName.UserName = "username";
factory.Credentials.UserName.Password = "password";
MyService.MyServiceInterface client = factory.CreateChannel();
// make use of client to call web service here...
BasicHttpBinding=new BasicHttpBinding();
binding.Security.Mode=BasicHttpSecurityMode.TransportWithMessageCredential;
Uri endpointAddress=新Uri(“https://server.com/Service.asmx");
ChannelFactory工厂=新的ChannelFactory(绑定,endpointAddress.ToString());
factory.Credentials.UserName.UserName=“UserName”;
factory.Credentials.UserName.Password=“Password”;
MyService.MyServiceInterface client=factory.CreateChannel();
//在此处使用客户端调用web服务。。。
也许可以展示一下你目前所拥有的,人们可以试着指出problems@Sunny:感谢您包含XML,让它工作的诀窍是什么?好的,很高兴我能提供帮助!(我正在为WCF考试学习,所以这些东西应该在我的脑海里是新鲜的:-)
BasicHttpBinding binding = new BasicHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.TransportWithMessageCredential;
Uri endpointAddress = new Uri("https://server.com/Service.asmx");
ChannelFactory<MyService.MyServiceInterface> factory = new ChannelFactory<MyService.MyServiceInterface>(binding, endpointAddress.ToString());
factory.Credentials.UserName.UserName = "username";
factory.Credentials.UserName.Password = "password";
MyService.MyServiceInterface client = factory.CreateChannel();
// make use of client to call web service here...