我遇到了WCF服务的问题。我不是这方面的专家,所以我决定创建一个新项目,然后看看它开始的时间。它从一个示例Service1.svc文件开始,当我点击F5时,它会调出WCF测试客户端。到目前为止一直这么好......直到我看到端点/绑定/无论如何定义。
但我在webconfig中完全没有看到任何关于Service1的内容。如果我复制了这个文件,但是将新文件中的类名更改为Service2并在点击F5之前选择它,那么它会向我抱怨并且WCF测试客户端看不到任何内容。
这是webconfig:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
</appSettings>
<!--
For a description of web.config changes see http://go.microsoft.com/fwlink/?LinkId=235367.
The following attributes can be set on the <httpRuntime> tag.
<system.Web>
<httpRuntime targetFramework="4.5.1" />
</system.Web>
-->
<system.web>
<compilation debug="true" targetFramework="4.5.1"/>
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="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>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
因此,如果关于Service1的webconfig中没有任何内容,那么当我提起它时,WCF测试客户端如何知道它?我在这里肯定很困惑......似乎webconfig中应该有更多东西。
答案 0 :(得分:1)
请refer这将有助于您了解如何创建服务端点。
<强>&#34;端点是与世界通信的门户。 所有WCF通信都通过端点进行。终点由三个部分组成。&#34; 地址,约束和合同
编辑
试试simplified configuration。如果您在.NET 4.0中创建项目,您将获得此简化模式。
答案 1 :(得分:0)
端点由explained here组成一些信息。前两个,由http://host:port/Service1.svc
的Web请求推断的地址和绑定以及合同由IService1.cs
定义,其中应包含描述您的服务提供的方法的接口。您的服务的实施位于Service1.svc.cs
。
web.config中的位只是为所有服务使用的所有行为指定了一些默认值。行为是描述服务产品细节的一种方式,比如它如何公开元数据,处理安全性等等。大多数情况都是默认的。
您可能会发现查看Service1.svc
中的实际内容(右键单击并选择查看标记)也很有帮助。
答案 2 :(得分:0)
您已经定义了WCF服务的基本ABC但是我正在共享我的WCF服务的示例web.config文件。请更新您的web.config文件,确保您的服务正常运行
<configuration>
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="false"/>
<services>
<service behaviorConfiguration="ServiceBehaviour" name="DataService.DataService">
<endpoint address="web" behaviorConfiguration="jsonBehavior" binding="webHttpBinding" bindingConfiguration="webHttpBindingWithJsonP" contract="DataService.IDataService"/>
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsHttpBinding" contract="DataService.IDataService" />
<endpoint address="soap" binding="basicHttpBinding" contract="DataService.IDataService"/>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="jsonBehavior">
<webHttp helpEnabled="true" faultExceptionEnabled="True" defaultBodyStyle="Bare" defaultOutgoingResponseFormat="Xml"/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<!-- To avoid disclosing metadata information, set the values below to false 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="true" httpHelpPageEnabled="True"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true" allowCookies="true">
<security mode="None"></security>
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</webHttpBinding>
<wsHttpBinding>
<binding name="wsHttpBinding" allowCookies="true">
<security mode="None"></security>
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>
<system.web>
<compilation debug="true" targetFramework="4.5"/>
<pages controlRenderingCompatibilityVersion="4.0"/>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>