我在论坛上搜索了她的一百个问题,但我无法实现我想要的目标。 我有一个.svc文件的web应用程序,它链接到Wfc srevice。我还有一个与服务通信的测试客户端。这是项目和IIS的图片:http://shrani.si/f/g/eG/4zKyZUj1/wcfsolutions.jpg
项目直接保存在Inetpub / wwwRoot中。我在IIS 7.5中托管这个。这一切都有效,但前提是我在visual studio中运行托管Web应用程序。通过这种方式,服务从Windows托盘开始,我可以在服务和客户端应用程序之间进行通信。
我的愿望是,为了实现这一点,当客户端实例化代理并调用服务时,wcf服务按需启动。因此,如果我想运行该服务,我不需要在我的服务器上安装instaled visual studio。这可能吗?人们在实践中如何做到这一点?
我也尝试在WAS中主持并遵循此说明http://msdn.microsoft.com/en-us/magazine/cc163357.aspx,但没有成功。
我的一些代码:
托管解决方案(3个项目)
1)Anketa PROJECT
-AnketeService.svc
<%@ ServiceHost Language="C#" Debug="true" Service="AnketeService.AnketeService" %>
-Web.config
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<bindings>
<wsHttpBinding>
<binding name="NoSecurityPlusRM" openTimeout="00:10:00" sendTimeout="00:10:00">
<reliableSession enabled="true" />
<security mode="None" />
</binding>
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="Metadata" name="AnketeService.AnketeService">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="NoSecurityPlusRM"
contract="AnketeService.IAnketeService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="Metadata">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="wsHttpBindingBehavior">
<callbackTimeouts transactionTimeout="23:59:59" />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
2)AnketeService PROJECT
-AnketeService.cs
[ServiceBehavior(Name="Ankete servis", InstanceContextMode=InstanceContextMode.PerCall , ConcurrencyMode=ConcurrencyMode.Single)]
public class AnketeService : IAnketeService
{
UsersItems allUsers = new UsersItems();
AnketaItems AnketaOfUserName = new AnketaItems();
public UsersItems getUsersNames()
{
return allUsers.ReturnData();
}
public AnketaItems getAnketeGledeUName(string userName)
{
return AnketaOfUserName.ReturnAnketeGledeUName(userName);
}
}
}
-IAnketeService.cs
[ServiceContract(Name = "AnketeService", Namespace = "http://MartinFri/Ankete/2011-2012")]
public interface IAnketeService
{
[OperationContract]
UsersItems getUsersNames();
[OperationContract]
AnketaItems getAnketeGledeUName(string userName);
}
3)AnketaTypes(不相关,只有类型类)
客户解决方案(1个项目)
1)AnketaClient PROJECT
我在这里制作添加服务参考 - &gt;本地主机:56507 / AnketeService.svc
-ClientConsumeWCF.cs
public partial class ClientConsumeWCF : System.Web.UI.Page
{
AnketeServiceClient client = new AnketeServiceClient("WSHttpBinding_AnketeService");
AnketaItems AItem = new AnketaItems();
protected void Page_Load(object sender, EventArgs e)
{
this.btnLoad.Click += new EventHandler(btnLoad_Click);
}
void btnLoad_Click(object sender, EventArgs e)
{
List<string> anketeList = new List<string>();
if (ddlUserji.SelectedItem != null)
{
AItem = client.getAnketeGledeUName(Convert.ToString(ddlUserji.SelectedItem));
List<AnketaItem> ankete = AItem.ListAnketaGledeUName;
GVAnkete.DataSource = ankete;
GVAnkete.DataBind();
}
AItem.UserFirstName = (Environment.MachineName).ToString();
TextBox1.Text = client.reciHello(AItem);
}
}
}
-Web.Config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_AnketeService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
<wsHttpBinding>
<binding name="WSHttpBinding_AnketeService" closeTimeout="00:10:00"
openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="true" />
<security mode="None">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:56507/AnketeService.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_AnketeService"
contract="AnketeServiceReference.AnketeService" name="WSHttpBinding_AnketeService" />
</client>
</system.serviceModel>
</configuration>
是否有人有良好指示或良好教程的链接? 我会很高兴有任何建议,如何处理。
谢谢,马丁