[英]silverlight is calling WCF service but not passing parameters
I have a WCF service in a project with the following setup 我在具有以下设置的项目中有WCF服务
//interface //接口
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);
}
}
// and the following implementation //和以下实现
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();
}
}
}
Here is the web.config file in the website application part of my solution that pertains to the wcf service 这是我的解决方案中与wcf服务有关的网站应用程序部分中的web.config文件
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
and the ServiceReference.clientconfig file in the silverlight project 和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>
//here is the calling code ... it is in an event that gets triggered on a button click //这是调用代码...它是在单击按钮时触发的事件中
ServiceReference1.Service1Client obj = new ServiceReference1.Service1Client();
obj.DoWorkAsync("Test");
The parameter is always being passed as null. 该参数始终作为null传递。 what is going wrong?
怎么了? I can't figure it out since I'm new to integrating WCF/silverlight/Asp.net.
由于我是集成WCF / silverlight / Asp.net的新手,所以我无法弄清楚。
Update your service reference again. 再次更新您的服务参考。 Try like this, In silverlight your method should have a completed event,
尝试这样,在Silverlight中,您的方法应该有一个完成事件,
ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
client.DoWorkCompleted += (a, ae) =>
{
};
client.DoWorkAsync("Test");
You might be exceeding the maxStringContentLength which is 8192 by default. 您可能超出了默认的maxStringContentLength,即8192。 See here:
看这里:
http://msdn.microsoft.com/en-us/library/ms731361(v=vs.110).aspx http://msdn.microsoft.com/zh-CN/library/ms731361(v=vs.110).aspx
http://msdn.microsoft.com/en-us/library/ms731325(v=vs.110).aspx http://msdn.microsoft.com/zh-CN/library/ms731325(v=vs.110).aspx
You may want to consider using binary message encoding as well. 您可能还需要考虑使用二进制消息编码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.