- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我将 Wcf 服务库 项目添加到解决方案中,它创建了 2 个类(Service1
、IService1
)和配置文件。现在我想将该服务添加到同一解决方案中的 Console 项目中。我单击“添加服务引用 -> 发现”,它找到了该服务。
当我创建 Windows 类库 项目并在那里创建与刚刚创建的 Wcf 服务库 项目相同的示例,然后尝试将其添加为对我的 的引用>Console 项目,因此点击 Discover 不会返回任何内容。为什么?
创建Wcf Service Library 项目或Windows Class Library 项目和在Wcf Service Library 中创建时有什么区别?
已编辑
仅当服务位于 Wcf 服务库 中时,Discover
才有效。但是一旦我转移到其他项目(Console、Class Library),Discover
就再也找不到它了。为什么?
app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="WcfServiceLibrary1.Service1">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8732/Design_Time_Addresses/WcfServiceLibrary1/Service1/" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address ="" binding="wsHttpBinding" contract="WcfServiceLibrary1.IService1">
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<!-- Metadata Endpoints -->
<!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
<!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Service1.cs
namespace WcfServiceLibrary1
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetData(int value);
[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);
// TODO: Add your service operations here
}
// Use a data contract as illustrated in the sample below to add composite types to service operations
[DataContract]
public class CompositeType
{
bool boolValue = true;
string stringValue = "Hello ";
[DataMember]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}
[DataMember]
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
}
}
IService.cs
namespace WcfServiceLibrary1
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
public CompositeType GetDataUsingDataContract(CompositeType composite)
{
if (composite == null)
{
throw new ArgumentNullException("composite");
}
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
}
}
最佳答案
经过一番检查后我得出结论,只有创建了WCF 服务库,您才可以使用Add Service Reference->Discover
按钮创建客户端,而无需显式运行主机,并且它会找到服务。
如果您创建的类库项目将包含您的服务文件,那么如果服务未托管(是未运行)。你应该运行主机,只有在它把服务地址放在地址栏并按Go
之后关于c# - 为什么在 "Windows Class Library"项目中创建时未发现 wcf 服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11432876/
在我们的数据库表上,我们使用两个唯一的非聚集索引来创建跨四个字段的唯一约束。我们使用两个,因为其中一个字段 ZipCode 是一个可为空的字段。如果表中存在一条包含 ZipCode 的 null 条目
我刚刚开始学习 Rails 3 教程,以便对框架有一点熟悉,但我在生成 schema.rb 时遇到了问题。我的操作系统是 Windows 7 x64、Ruby 1.9.2、MySQL2 gem 0.2
我是一名优秀的程序员,十分优秀!