这里定义的端点在哪里
本文关键字:在哪里 端点 定义 这里 | 更新日期: 2023-09-27 18:07:04
我在使用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>
所以如果在webconfig中没有关于Service1的任何内容,那么当我把它打开时,WCF测试客户端如何知道它?我真的很困惑……看起来webconfig里应该有更多的东西
关于如何创建服务端点,请参考本文。
"端点是与世界通信的门户。所有的WCF通信都是通过端点进行的。终点由三个部分组成。"地址、约束力和合同
编辑
尝试简化配置。如果你在。net 4.0中创建项目,你会得到这种简化的模式。
端点由几条信息组成,如下所述。前两个,地址和绑定是由web请求推断到http://host:port/Service1.svc
的,契约是由IService1.cs
定义的,它应该包含一个描述你的服务提供的方法的接口。您的服务在Service1.svc.cs
中实现
web中的位。Config只是为所有服务使用的所有行为指定了一些默认值。行为是描述服务提供细节的一种方式,比如它如何公开元数据、处理安全性等。虽然大多数默认值都很体面。
您可能会发现查看Service1.svc
中的实际内容(右键单击并选择查看标记)也很有帮助。
您已经定义了WCF服务的基本ABC,但是我正在分享示例web。我的WCF服务配置文件。请更新您的网站。配置文件,我确定你的服务将工作
<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>