【发布时间】:2014-01-05 05:14:49
【问题描述】:
我在具有以下设置的项目中有 WCF 服务
//接口
namespace AttendanceSystem
{
// 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]
void DoWork(string s);
}
}
//和下面的实现
namespace AttendanceSystem
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
public class Service1 : IService1
{
public void DoWork(string s)
{
StreamWriter file = new StreamWriter(@"C:\users\waqasjafri\desktop\test.txt");
if (s == null)
{
file.WriteLine("value is null");
}
else
{
file.WriteLine("value is not null");
}
file.Close();
}
}
}
这是我的解决方案的网站应用程序部分中与 wcf 服务相关的 web.config 文件
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
以及 silverlight 项目中的 ServiceReference.clientconfig 文件
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:48886/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"
name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>
//这里是调用代码......它是在一个按钮点击触发的事件中
ServiceReference1.Service1Client obj = new ServiceReference1.Service1Client();
obj.DoWorkAsync("Test");
参数始终作为 null 传递。出了什么问题?我无法弄清楚,因为我是集成 WCF/silverlight/Asp.net 的新手。
【问题讨论】:
-
你能把调用代码也贴出来吗?
-
刚刚做了?你怎么看?
-
您能否使用 Fiddler 检查您的请求,然后查看请求是否正在发出并包含您的值。如果是这样,那么问题出在服务器上。请发布您的服务器端端点配置详细信息。
-
好吧,当我在服务接口中创建数据协定并使用类似 ServiceReference1.Item i = new ServiceReference1.Item { val = "Test"};然后将其传递给方法。不知道为什么字符串没有在相同的设置下通过。
标签: c# asp.net wcf silverlight