C# 无法正确引用wcf数据服务
我有几个问题可能是相关的,也可能不是。我注意到,当我在Visual Studio中使用Add Service Reference向我的数据服务添加引用时,它生成的Reference.cs不会编译。它抱怨缺少名称空间。我可以在编译时修复它,但每次我更新引用时都会发生这种情况,而且在其他级别上也令人担忧,例如“这会导致其他问题吗?” 我还注意到,在执行此操作时,我的主机服务器(承载数据服务的控制台应用程序)会记录以下内容:C# 无法正确引用wcf数据服务,c#,wcf,dataservice,C#,Wcf,Dataservice,我有几个问题可能是相关的,也可能不是。我注意到,当我在Visual Studio中使用Add Service Reference向我的数据服务添加引用时,它生成的Reference.cs不会编译。它抱怨缺少名称空间。我可以在编译时修复它,但每次我更新引用时都会发生这种情况,而且在其他级别上也令人担忧,例如“这会导致其他问题吗?” 我还注意到,在执行此操作时,我的主机服务器(承载数据服务的控制台应用程序)会记录以下内容: An exception occurred [System.Data.Ser
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>
有什么想法吗?非常感谢
谢谢我想你接错地址了。你有一个基本地址
<add baseAddress="http://localhost:8752/DataService/"/>
你有没有试着连接到那里
我不确定您是否可以拥有一个带有WCF REST服务的“mex”元数据交换端点。我的印象是,WCF数据服务的客户端代理通过HTTP端点的特殊URL调用获取其元数据。因此,也可以尝试从您的配置中删除它(并且您不能在该服务上使用svcuti
,我相信-svcuti仅用于SOAP服务调用,如果我没有弄错的话)
另外,由于您使用的是webHttpBinding
和自托管,因此需要添加webHttp
行为:
<behavior name="behaviour">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="10"/>
<webHttp />
</behavior>
如果您执行这两个步骤,我认为您应该能够获得WCF数据服务。试试看,让我们知道 我添加了webhttp端点行为,但没有发现任何区别。我不确定的另一件事是,我在同一个过程中也有一个“正常”的WCF服务(使用[ServiceContract])。我想知道这个“错误”是否真的正常-Add服务引用似乎只是在尝试一系列URI变体,直到其中一个能够工作,并且它生成的代码经过一些编辑就可以了。我将尝试一些基本测试,看看它是否真的有效:)
<add baseAddress="http://localhost:8752/DataService/"/>
<endpoint address="svc" binding="webHttpBinding"
http://localhost:8752/DataService/svc
<behavior name="behaviour">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="10"/>
<webHttp />
</behavior>