2010-02-26 62 views
2

我遇到了几个可能相关或可能不相关的问题。我注意到,当我使用Visual Studio中的Add Service Reference添加对我的数据服务的引用时,它生成的reference.cs不能编译。它抱怨缺少名称空间。我可以修复它,但是每次更新引用时都会发生这种情况,而且它也担心其他级别,比如“这会导致其他问题”。无法正确引用wcf数据服务

我也注意到,当我这样做,我的主机服务器(托管的数据服务的控制台应用程序)记录此:

An exception occurred [System.Data.Services.DataServiceException] :: The URL 
representing the root of the service only supports GET requests. 

这是服务的配置:

<service behaviorConfiguration="behaviour" name="StatsPlus.Server.HostedServices.SPDataServiceHost"> 
    <endpoint address="svc" binding="webHttpBinding" contract="System.Data.Services.IRequestHandler" /> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 

    <host> 
     <baseAddresses> 
     <add baseAddress="http://localhost:8752/DataService/"/> 
     </baseAddresses> 
    </host> 
    </service> 

而行为:

<behavior name="behaviour"> 
     <serviceMetadata httpGetEnabled="true"/> 
     <serviceDebug includeExceptionDetailInFaults="true"/> 
     <dataContractSerializer maxItemsInObjectGraph="10"/> 
    </behavior> 

当我尝试运行svcutil http://localhost:8752/DataService/,我得到这样的:

HTTP GET Error 
URI: http://localhost:8752/DataService 
There was an error downloading 'http://localhost:8752/DataService'. 
The request failed with HTTP status 405: Method Not Allowed. 

任何想法?非常感谢

谢谢

回答

2

我想你连接到一个错误的地址。你有一个基本地址

<add baseAddress="http://localhost:8752/DataService/"/> 

,并在一个相对的端点地址的顶部

<endpoint address="svc" binding="webHttpBinding" 

让你完整的URL将是两者的结合:

http://localhost:8752/DataService/svc 

你有没有尝试在那里连接?

我不确定您是否真的可以拥有带WCF REST服务的“mex”元数据交换端点。我的印象是WCF数据服务的客户端代理通过来自HTTP端点的特殊URL调用获取其元数据。因此,也许尝试从你的配置中删除它(并且你不能在该服务上使用svcutil,我相信 - 如果我没有弄错,svcutil仅适用于SOAP服务调用)。

而且,由于你使用webHttpBinding和自托管,你需要添加webHttp行为:

<behavior name="behaviour"> 
    <serviceMetadata httpGetEnabled="true"/> 
    <serviceDebug includeExceptionDetailInFaults="true"/> 
    <dataContractSerializer maxItemsInObjectGraph="10"/> 
    <webHttp /> 
</behavior> 

如果你做这两个步骤,我想你应该能够得到你的WCF数据服务。试试吧,让我们知道!

+0

我已经添加了webhttp端点行为,但我没有看到任何区别。 另一件我不确定的事情是我在同一个进程中也有一个“正常的”WCF服务(使用[ServiceContract])。 我想知道这个“错误”实际上是否正确 - 添加服务引用似乎只是尝试一堆URI变体,直到一个工程,并且它生成的代码是一些编辑罚款。我要去尝试一些基本的测试,看看它是否真的有效:) – JohnL 2010-02-27 00:33:59