您好,感谢您的阅读。
我正在尝试在IIS 7.5中托管一个服务,该服务暴露了多个端点。
我感觉问题出在我的web.config中,但我会在这里发布我的服务代码。没有接口文件,因为我使用的是WCF 4的新功能,也没有.svc文件。
根据我的理解,所有路由都使用RouteTable功能在Global.asax.cs中处理。
无论如何,进入code / config -
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
// NOTE: If the service is renamed, remember to update the global.asax.cs file
public class Service1
{
// TODO: Implement the collection resource that will contain the SampleItem instances
[WebGet(UriTemplate = "HelloWorld")]
public string HelloWorld()
{
// TODO: Replace the current implementation to return a collection of SampleItem instances
return "Hello World!";
}
}
现在,我认为需要进行更改的配置(我不确定是否需要保留standardEndpoints块,但无论有没有它我仍然会收到错误消息。 -
<services>
<service name="AiSynthDocSvc.Service1" behaviorConfiguration="HttpGetMetadata">
<endpoint name="rest"
address=""
binding="webHttpBinding"
contract="AiSynthDocSvc.Service1"
behaviorConfiguration="REST" />
<endpoint name="soap"
address="soap"
binding="basicHttpBinding"
contract="AiSynthDocSvc.Service1" />
<endpoint name="mex"
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="REST">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="HttpGetMetadata">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<standardEndpoints>
<webHttpEndpoint>
<!--
Configure the WCF REST service base address via the global.asax.cs file and the default endpoint
via the attributes on the <standardEndpoint> element below
-->
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/>
</webHttpEndpoint>
</standardEndpoints>
Global.asax.cs文件一个人留下。
我再次确定它与我的配置有关。当我尝试访问任何定义的端点时,我得到的错误是 -
''处的端点没有与None MessageVersion的绑定。 'System.ServiceModel.Description.WebHttpBehavior'仅适用于WebHttpBinding或类似绑定。
任何人对此都有任何想法吗?
谢谢,
Zachary Carter
答案 0 :(得分:7)
好的,我试图复制你的东西 - 对我来说就像一个魅力: - )
RegisterRoutes
global.asax.cs
来电
当我从Visual Studio中启动Web应用程序时,我会在http://localhost:3131/
上找到Cassini(内置的Web服务器) - 这可能会对您的情况持谨慎态度。
现在,我可以使用第二个浏览器窗口轻松导航,我对此网址做了简单的回复:
http://localhost:3131/Service1/HelloWorld
+--------------------+
from Cassini
+--------+
name (first param) in ServiceRoute registration
+-----------+
from your URI template on the WebGet attribute
相同的网址是否适用于您?
更新:这是我的配置 - 我可以使用REST连接到浏览器中的http://localhost:3131/Service1/HelloWorld
,我可以使用WCF测试客户端连接到http://localhost:3131/Service1/soap
来创建SOAP call(我的Service1
位于RestWebApp
名称空间中 - 因此我的服务和合同名称与您的名称有所不同 - 但除此之外,我认为它与您自己的配置相同):
<system.serviceModel>
<serviceHostingEnvironment
aspNetCompatibilityEnabled="true" />
<services>
<service name="RestWebApp.Service1" behaviorConfiguration="Meta">
<endpoint name="rest"
address=""
binding="webHttpBinding"
contract="RestWebApp.Service1"
behaviorConfiguration="REST" />
<endpoint name="SOAP"
address="soap"
binding="basicHttpBinding"
contract="RestWebApp.Service1" />
<endpoint name="mex"
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="REST">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="Meta">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<standardEndpoints>
<webHttpEndpoint>
<!--
Configure the WCF REST service base address via the global.asax.cs file and the default endpoint
via the attributes on the <standardEndpoint> element below
-->
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/>
</webHttpEndpoint>
</standardEndpoints>
</system.serviceModel>
答案 1 :(得分:0)
谢谢你,这给了我很多帮助。
我的问题是我配置了包含webHttp的默认行为。给它命名=“REST”并设置我的webHttpBinding端点behaviourConfiguration =“REST”后我没有其他错误。
<system.serviceModel>
<bindings>
<customBinding>
<binding name="CustomBinding_IMobileService">
<binaryMessageEncoding />
<httpTransport />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://localhost:6862/silverlight/services/MobileService.svc"
binding="customBinding" bindingConfiguration="CustomBinding_IMobileService"
contract="AlchemyMobileService.IMobileService" name="CustomBinding_IMobileService" />
</client>
<services>
<service name="MobileService.Alchemy">
<endpoint address="http://localhost:8732/mobileservice" binding="webHttpBinding" contract="MobileService.IAlchemy" behaviorConfiguration="REST">
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="REST">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>