从 C# 代码配置 Web 服务端点和合同?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/688988/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Configuring a web service endPoint and contract from C# code?
提问by Lasse V. Karlsen
Edit: I decided to just convert this to a normal web page, as I only need to provide one integer parameter and retrieve a string.
编辑:我决定将其转换为普通网页,因为我只需要提供一个整数参数并检索一个字符串。
I'll leave the question open if anyone has a good answer.
如果有人有好的答案,我会留下这个问题。
I have a web service that I want to call, but because this must be called from a plugin to another system, an application config file with all the configuration in won't do, as the plugin system doesn't read that file at all, just the DLL.
我有一个我想调用的 Web 服务,但是因为它必须从一个插件调用到另一个系统,所以包含所有配置的应用程序配置文件将无法执行,因为插件系统根本不读取该文件,只是DLL。
So, the question is, how can I take the relevant parts from the config file and translate this to code instead?
所以,问题是,如何从配置文件中获取相关部分并将其转换为代码?
The parts I probably need to convert are:
我可能需要转换的部分是:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="TooltipServiceSoap" 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="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:2952/TooltipService.asmx"
binding="basicHttpBinding" bindingConfiguration="TooltipServiceSoap"
contract="TooltipService.TooltipServiceSoap" name="TooltipServiceSoap" />
</client>
</system.serviceModel>
The URL and such will of course change, but that's for me to figure out if someone can just point me in the right direction on how to get the necessary code into the application so that if I delete the application config file, it will still work.
URL 等当然会改变,但我要弄清楚是否有人可以指出我如何将必要的代码导入应用程序的正确方向,以便如果我删除应用程序配置文件,它仍然可以工作.
采纳答案by Keith
This is on a similar issue and might help: Making WCF easier to configure
这是在一个类似的问题上,可能会有所帮助:使 WCF 更容易配置
I wanted to have an application with little or no client config required - just point it at the server and have it connect.
我想要一个几乎不需要客户端配置的应用程序 - 只需将它指向服务器并让它连接。
回答by Avanish GUpta
I used following configuration in web.configfile for uploading file size more than 64 KB(Default) through REST Service.
我在web.config文件中使用以下配置通过 REST 服务上传超过 64 KB(默认)的文件。
<system.serviceModel>
<services>
<service name="Service">
<endpoint
address=""
binding="webHttpBinding" bindingConfiguration="FileTransferServicesBinding"
contract="IService"/>
</service>
</services>
<bindings>
<webHttpBinding >
<binding name="FileTransferServicesBinding" maxBufferSize="10242880" maxReceivedMessageSize="10242880">
<readerQuotas maxStringContentLength="10242880" maxArrayLength="10242880" />
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>
<system.web>
<httpRuntime maxRequestLength="65536" executionTimeout="36000"/>
</System.Web>

