首页 新闻 搜索 专区 学院

在WEB项目中添加service reference报错

0
悬赏园豆:10 [已关闭问题] 关闭于 2010-09-08 15:44

最近在弄WCF的过程中,想添加service reference,但是报以下错误。

There was an error downloading 'http://localhost:3502/ServiceHost/Sample/Calculator.svc'.The server committed a protocol violation. Section=ResponseStatusLineMetadata contains a reference that cannot be resolved: 'http://localhost:3502/ServiceHost/Sample/Calculator.svc'.The server committed a protocol violation. Section=ResponseStatusLineThe server committed a protocol violation. Section=ResponseStatusLine

下面为报错截图:

一直报这个错,不知道怎么回事,首先在网上查

The server committed a protocol violation. Section=ResponseStatusLine;网上的一种解决方案是:

<system.net>
<settings>
<httpWebRequest useUnsafeHeaderParsing="true" />
</settings>
</system.net>
但是在web.config中配置后,仍然不能解决。求解,为什么会报这种错误。


补充:
ICalculator.cs类:
namespace WCF.ServiceLib.Sample
{
[ServiceContract]
public interface ICalculator
{
[OperationContract]
double Add(double x, double y);
}
}

 

Calculator.cs类:
namespace WCF.ServiceLib.Sample
{
public class Calculator : ICalculator
{
public double Add(double x, double y)
{
return x + y;
}
}
}

 

web.config配置:
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name ="CalculatorBehavior">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<!--name - 提供服务的类名-->
<!--behaviorConfiguration - 指定相关的行为配置-->
<service name="WCF.ServiceLib.Sample.Calculator" behaviorConfiguration="CalculatorBehavior">
<!--address - 服务地址-->
<!--binding - 通信方式-->
<!--contract - 服务契约-->
<endpoint address="" binding="basicHttpBinding" contract="WCF.ServiceLib.Sample.ICalculator" />
</service>
</services>
</system.serviceModel>
</configuration>

 

这个就是我的Web Service相关文件,直接运行结果图
运行都是正确的,就是不能添加service reference服务。

单击之后能返回完整的服务描述。如下:
<?xml version="1.0" encoding="utf-8" ?>
-
<wsdl:definitions name="Calculator" targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:tns="http://tempuri.org/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata">
-
<wsdl:types>
-
<xsd:schema targetNamespace="http://tempuri.org/Imports">
<xsd:import schemaLocation="http://localhost:3502/ServiceHost/Sample/Calculator.svc?xsd=xsd0" namespace="http://tempuri.org/" />
<xsd:import schemaLocation="http://localhost:3502/ServiceHost/Sample/Calculator.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/" />
</xsd:schema>
</wsdl:types>
-
<wsdl:message name="ICalculator_Add_InputMessage">
<wsdl:part name="parameters" element="tns:Add" />
</wsdl:message>
-
<wsdl:message name="ICalculator_Add_OutputMessage">
<wsdl:part name="parameters" element="tns:AddResponse" />
</wsdl:message>
-
<wsdl:portType name="ICalculator">
-
<wsdl:operation name="Add">
<wsdl:input wsaw:Action="http://tempuri.org/ICalculator/Add" message="tns:ICalculator_Add_InputMessage" />
<wsdl:output wsaw:Action="http://tempuri.org/ICalculator/AddResponse" message="tns:ICalculator_Add_OutputMessage" />
</wsdl:operation>
</wsdl:portType>
-
<wsdl:binding name="BasicHttpBinding_ICalculator" type="tns:ICalculator">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
-
<wsdl:operation name="Add">
<soap:operation soapAction="http://tempuri.org/ICalculator/Add" style="document" />
-
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
-
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
-
<wsdl:service name="Calculator">
-
<wsdl:port name="BasicHttpBinding_ICalculator" binding="tns:BasicHttpBinding_ICalculator">
<soap:address location="http://localhost:3502/ServiceHost/Sample/Calculator.svc" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

 

coodoing的主页 coodoing | 初学一级 | 园豆:185
提问于:2010-09-02 21:05
< >
分享
所有回答(1)
0

服务包含无法解析的引用

把你的服务端代码和配置文件贴出来。

Launcher | 园豆:45045 (高人七级) | 2010-09-02 21:12
ICalculator.cs类: namespace WCF.ServiceLib.Sample { [ServiceContract] public interface ICalculator { [OperationContract] double Add(double x, double y); } } Calculator.cs类: namespace WCF.ServiceLib.Sample { public class Calculator : ICalculator { public double Add(double x, double y) { return x + y; } } } web.config配置: <?xml version="1.0"?> <configuration> <system.serviceModel> <behaviors> <serviceBehaviors> <behavior name ="CalculatorBehavior"> <serviceMetadata httpGetEnabled="true"/> </behavior> </serviceBehaviors> </behaviors> <services> <!--name - 提供服务的类名--> <!--behaviorConfiguration - 指定相关的行为配置--> <service name="WCF.ServiceLib.Sample.Calculator" behaviorConfiguration="CalculatorBehavior"> <!--address - 服务地址--> <!--binding - 通信方式--> <!--contract - 服务契约--> <endpoint address="" binding="basicHttpBinding" contract="WCF.ServiceLib.Sample.ICalculator" /> </service> </services> </system.serviceModel> </configuration>
支持(0) 反对(0) coodoing | 园豆:185 (初学一级) | 2010-09-02 22:35
@DCBI:添加一个元数据终结点,如下: <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 记得在IE中多点一下,也就是查看如下url: http://localhost:3502/ServiceHost/Sample/Calculator.svc?wsdl 看能否返回完整的服务描述.
支持(0) 反对(0) Launcher | 园豆:45045 (高人七级) | 2010-09-03 08:56
@Galactica:添加了一个元数据终结点: <service name="WCF.ServiceLib.Sample.Calculator" behaviorConfiguration="CalculatorBehavior"> <endpoint address="" binding="basicHttpBinding" contract="WCF.ServiceLib.Sample.ICalculator" /> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint> </service> 但还是出现开始的问题。。。。
支持(0) 反对(0) coodoing | 园豆:185 (初学一级) | 2010-09-03 10:28
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册