C# IIS 7.5中带有REST/SOAP端点的WCF 4服务
您好,谢谢您的阅读 我正在尝试获取一个托管在IIS 7.5中的服务,该服务公开了多个端点 我感觉问题出在我的web.config中,但我会在这里发布我的服务代码。没有接口文件,因为我使用的是WCF 4的更新功能,所以也没有.svc文件 据我所知,所有路由都在Global.asax.cs中使用RouteTable功能进行处理 不管怎样,在代码/配置中-C# IIS 7.5中带有REST/SOAP端点的WCF 4服务,c#,wcf,rest,soap,C#,Wcf,Rest,Soap,您好,谢谢您的阅读 我正在尝试获取一个托管在IIS 7.5中的服务,该服务公开了多个端点 我感觉问题出在我的web.config中,但我会在这里发布我的服务代码。没有接口文件,因为我使用的是WCF 4的更新功能,所以也没有.svc文件 据我所知,所有路由都在Global.asax.cs中使用RouteTable功能进行处理 不管怎样,在代码/配置中- [ServiceContract] [AspNetCompatibilityRequirements(RequirementsMode = Asp
[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)好吧,我试着复制你的东西——对我来说就像一个符咒:-)
- 我使用了你的服务等级-没有变化
- 我在
global.asax.cs
http://localhost:3131/
-在您的情况下,这可能会引起警惕
现在,我可以通过第二个浏览器窗口轻松地导航到那里,我确实得到了关于此URL的简单响应:
http://localhost:3131/Service1/HelloWorld
+--------------------+
from Cassini
+--------+
name (first param) in ServiceRoute registration
+-----------+
from your URI template on the WebGet attribute
相同的URL对你有用吗
更新:这是我的配置-我可以连接到http://localhost:3131/Service1/HelloWorld
在浏览器中使用REST,我可以连接到http://localhost:3131/Service1/soap
使用WCF测试客户端进行SOAP调用(我的Service1
位于RestWebApp
命名空间中-因此我的服务和合同名称与您的略有不同-但除此之外,我相信它与您自己的配置相同):
谢谢你,这对我帮助很大 在我的案例中,问题是我配置了一个包含webHttp的默认行为。在给它命名为“REST”并设置了webHttpBinding端点BehaviorConfiguration=“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>
您使用什么URL访问您的服务?另外:您说您没有*.svc文件-那么您的服务是如何激活的?您需要一个*.svc文件,或者您的配置中需要一个标记。该服务部署到端口80上的默认网站上,因此只需访问它即可。此外,在没有.svc文件的情况下创建服务的功能也是一个关键NET 4.0中的w功能。没有点击svc文件,而是添加了一个新的类来正确地将请求路由到相应的服务。您能告诉我们您是如何将服务添加到路由表中的吗?该表很可能位于
global.asax.cs
-您说您没有触摸该表-因此我想知道……当然-私有无效RegisterRoutes(){//通过替换RouteTable.Routes.Add(new ServiceRoute(“Service1”,new WebServiceHostFactory(),typeof(Service1));)下面的“Service1”字符串来编辑Service1的基址Marc,如果我不使用配置文件,肯定会这样。我的问题是,只要我尝试公开配置为使用basicHttpBinding的其他端点,原始REST端点就会失效,并且新公开的端点也找不到。我的soap端点看起来像-但导航到会产生以下错误消息-en“”处的dpoint没有None MessageVersion的绑定。“System.ServiceModel.Description.WebHttpBehavior”仅用于WebHttpBinding或类似绑定。我认为这与将行为配置设置为WebHttpBinding且将端点行为配置设置为使用basicHttpBindin的服务有关g、 @Zachary Carter:我不这么认为-你已经给你的端点行为(其中包含webHttp
)起了一个名字,所以只有当你在标签上真正定义它时,才应该使用它。或者你真的没有发布你真正的配置??你有默认的端点行为(没有名字)我想我包括了它。我想这可能是造成问题的原因-
<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>