C# wcf web.config 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8765798/
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
wcf web.config file
提问by Guillermo Varini
ok, my file have this structure.
好的,我的文件有这个结构。
<system.serviceModel>
<services>
<service name="ManyaWCF.ServiceManya" behaviorConfiguration="ServiceBehaviour">
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address="" binding="webHttpBinding" contract="ManyaWCF.IServiceManya" behaviorConfiguration="web">
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true" />
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
i got the same web.config in other wcf and worked like a champ, ofc with different folders and files. my folder structure is the following.
我在其他 wcf 中得到了相同的 web.config 并且像冠军一样工作,ofc 使用不同的文件夹和文件。我的文件夹结构如下。


When i try to play it i get this,
当我尝试玩它时,我得到了这个,
Service
This is a Windows ? Communication Foundation.
The metadata publishing for this service is currently disabled.
If you access the service, you can enable metadata publishing by completing the following steps to modify the configuration file or web application:
1. Create the following service behavior configuration, or add the item to a configuration <serviceMetadata> existing service behavior:
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceTypeBehaviors">
httpGetEnabled="true" <serviceMetadata />
</ Behavior>
</ ServiceBehaviors>
</ Behaviors>
2. Add the behavior configuration to the service:
name="MyNamespace.MyServiceType" <service behaviorConfiguration="MyServiceTypeBehaviors">
Note: The service name must match the name of the configuration for the service implementation.
3. Add the following to end service configuration:
binding="mexHttpBinding" contract="IMetadataExchange" <endpoint address="mex" />
Note: the service must have an http base address to add this.
Here is an example of a service configuration file with metadata publishing enabled:
<configuration>
<system.serviceModel>
<services>
<! - Note: the service name must match the name of the configuration for the service implementation. ->
name="MyNamespace.MyServiceType" <service behaviorConfiguration="MyServiceTypeBehaviors">
<! - Add the following end. ->
<! - Note: the service must have an http base address to add this. ->
binding="mexHttpBinding" contract="IMetadataExchange" <endpoint address="mex" />
</ Service>
</ Services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceTypeBehaviors">
<! - Add the following item to the service behavior configuration. ->
httpGetEnabled="true" <serviceMetadata />
</ Behavior>
</ ServiceBehaviors>
</ Behaviors>
</ System.serviceModel>
</ Configuration>
For more information about publishing metadata, see the following documentation: http://go.microsoft.com/fwlink/?LinkId=65455 (may be in English).
so, i only did 1 wcf and worked fine with same web.conif. My luck of exp and knowledge about this is killing me. Any clue?
所以,我只做了 1 wcf 并且使用相同的 web.conif 工作正常。我的经验和知识的运气正在杀死我。有什么线索吗?
Thx in advance.
提前谢谢。
采纳答案by Elian Ebbing
As far as I know, you only need the endpoint with the mexHttpBindingif you want to expose the WSDL to clients. Visual Studio (or wcfutil.exe) needs the WSDL description to create the webservice client classes.
据我所知,mexHttpBinding如果要将 WSDL 公开给客户端,则只需要带有 的端点。Visual Studio(或 wcfutil.exe)需要 WSDL 描述来创建 Web 服务客户端类。
After these webservice client classes are created, you shouldn't need to expose the WSDL anymore.
在创建这些 webservice 客户端类之后,您应该不再需要公开 WSDL。
UPDATE:The <service>element in your configuration file should look like this:
更新:<service>配置文件中的元素应如下所示:
<service name="ManyaWCF.ServiceManya" behaviorConfiguration="ServiceBehaviour">
<endpoint address="" binding="webHttpBinding"
contract="ManyaWCF.IServiceManya" behaviorConfiguration="web" />
<endpoint address="mex" binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
回答by RandyMohan
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpRuntime maxRequestLength="1048576" executionTimeout="3600" />
</system.web>
<appSettings>
</appSettings>
<connectionStrings>
<add name="SQLConnect" connectionString="Your_Connection_String";User id=sa;Password=welcome3#"/>
</connectionStrings>
<system.serviceModel>
<services>
<service name="WCFRestService.RestServiceSvc" behaviorConfiguration="serviceBehavior">
<endpoint address="" bindingConfiguration="secureHttpBinding" binding="webHttpBinding" contract="WCFRestService.IRestServiceSvc" behaviorConfiguration="web"></endpoint>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="secureHttpBinding"
maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647"
maxBufferSize="2147483647" transferMode="Streamed">
</binding>
</webHttpBinding>
</bindings>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<httpProtocol>
<customHeaders>
</customHeaders>
</httpProtocol>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
<directoryBrowse enabled="true" />
</system.webServer>
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="50000000"/>
</webServices>
</scripting>
</system.web.extensions>
</configuration>

