我新建了wcf服务。申明两个接口,都实现了。
http://localhost:8731/Design_Time_Addresses/WcfServiceLibrary1/Service1/
http://localhost:8731/Design_Time_Addresses/WcfServiceLibrary1/MessageHello/为什么在另外项目添加服务引用的时候,只能找到Service1,而找不到MessageHello服务的配置文件
<baseAddresses>
<add baseAddress = "http://localhost:8731/Design_Time_Addresses/WcfServiceLibrary1/Service1/" />
</baseAddresses> <baseAddresses>
<add baseAddress = "http://localhost:8731/Design_Time_Addresses/WcfServiceLibrary1/MessageHello/" />
</baseAddresses>
都加上了。在IE中直接输入地址,Service1可以访问,MessageHello报400错
http://localhost:8731/Design_Time_Addresses/WcfServiceLibrary1/Service1/
http://localhost:8731/Design_Time_Addresses/WcfServiceLibrary1/MessageHello/为什么在另外项目添加服务引用的时候,只能找到Service1,而找不到MessageHello服务的配置文件
<baseAddresses>
<add baseAddress = "http://localhost:8731/Design_Time_Addresses/WcfServiceLibrary1/Service1/" />
</baseAddresses> <baseAddresses>
<add baseAddress = "http://localhost:8731/Design_Time_Addresses/WcfServiceLibrary1/MessageHello/" />
</baseAddresses>
都加上了。在IE中直接输入地址,Service1可以访问,MessageHello报400错
IMessagingHello.cs
[ServiceContract]
interface IMessagingHello
{
[OperationContract]
CustomMessage Hello(HelloGreetingMessage msg);
}MessageHello.cs
public class MessageHello:IMessagingHello
{
public CustomMessage Hello(HelloGreetingMessage msg)
{
Console.WriteLine("Caller sent: " + msg.Greeting);
CustomMessage customMessage = new CustomMessage();
customMessage.Response = "Service Received: " + msg.Greeting;
customMessage.ExtraValues = string.Format("Served by object {0}. ", this.GetHashCode().ToString());
Console.WriteLine("Returned response message.");
return customMessage;
}
} [MessageContract]
public class CustomMessage
{
private string localResponse = string.Empty;
private string extra = string.Empty;
[MessageBodyMember(Name = "abb",
Namespace = "http://www.xxx.com")]
public string Response
{
get { return localResponse; }
set { localResponse = value; }
} [MessageBodyMember(Name = "cccc",
Namespace = "http://www.xxx.com")]
public string ExtraValues
{
get { return extra; }
set { extra = value; }
}
} [MessageContract]
public class HelloGreetingMessage
{
private string localGreeting;
[MessageBodyMember(Name = "ddddd",
Namespace = "http://www.xxx.com")]
public string Greeting
{
get { return localGreeting; }
set { localGreeting = value; }
}
}
在服务“MessageHello”实现的协定列表中找不到协定名称“WcfServiceLibrary1.IMessageHello”楼上的哥们帮忙再看看
<system.web>
<compilation debug="true" />
</system.web>
<!-- 部署服务库项目时,必须将配置文件的内容添加到
主机的 app.config 文件中。System.Configuration 不支持库的配置文件。-->
<system.serviceModel>
<services>
<service name="WcfServiceLibrary1.Service1" behaviorConfiguration="WcfServiceLibrary1.Service1Behavior">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8731/Design_Time_Addresses/WcfServiceLibrary1/Service1/" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- 除非完全限定,否则地址将与上面提供的基址相关 -->
<endpoint address ="" binding="wsHttpBinding" contract="WcfServiceLibrary1.IService1">
<!--
部署时,应删除或替换下列标识元素,以反映
在其下运行部署服务的标识。删除之后,WCF 将
自动推导相应标识。
-->
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<!-- Metadata Endpoints -->
<!-- 元数据交换终结点由服务用于向客户端做自我描述。-->
<!-- 此终结点不使用安全绑定,应在部署前确保其安全或将其删除-->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
<service name="WcfServiceLibrary1.MessageHello" behaviorConfiguration="WcfServiceLibrary1.Service1Behavior">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8731/Design_Time_Addresses/WcfServiceLibrary1/MessageHello/" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- 除非完全限定,否则地址将与上面提供的基址相关 -->
<endpoint address ="" binding="wsHttpBinding" contract="WcfServiceLibrary1.IMessageHello">
<!--
部署时,应删除或替换下列标识元素,以反映
在其下运行部署服务的标识。删除之后,WCF 将
自动推导相应标识。
-->
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<!-- Metadata Endpoints -->
<!-- 元数据交换终结点由服务用于向客户端做自我描述。-->
<!-- 此终结点不使用安全绑定,应在部署前确保其安全或将其删除-->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfServiceLibrary1.Service1Behavior">
<!-- 为避免泄漏元数据信息,
请在部署前将以下值设置为 false 并删除上面的元数据终结点 -->
<serviceMetadata httpGetEnabled="True"/>
<!-- 要接收故障异常详细信息以进行调试,
请将下值设置为 true。在部署前
设置为 false 以避免泄漏异常信息-->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>我检查了n次了,没发现有差别
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>includeExceptionDetailInFaults="True"这个改为true看看报什么错误
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<services>
<service name="WcfServiceLibrary1.Service1" behaviorConfiguration="WcfServiceLibrary1.Service1Behavior">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8731/Design_Time_Addresses/WcfServiceLibrary1/Service1/" />
</baseAddresses>
</host>
<endpoint address ="Service1" binding="wsHttpBinding" contract="WcfServiceLibrary1.IService1">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
<service name="WcfServiceLibrary1.MessageHello" behaviorConfiguration="WcfServiceLibrary1.MessageHelloBehavior">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8731/Design_Time_Addresses/WcfServiceLibrary1/MessageHello/" />
</baseAddresses>
</host>
<endpoint address ="MessageHello" binding="wsHttpBinding" contract="WcfServiceLibrary1.IMessageHello">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfServiceLibrary1.Service1Behavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
<behavior name="WcfServiceLibrary1.MessageHelloBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>