WCF 双打数组未成功调用 [英] WCF array of doubles not called successfully
问题描述
所以我设法使用 SOAP 没问题,但我很难使用 WCF 来做同样的工作.
So I managed to use SOAP no problem but I am having difficulty using WCF to do the same job.
我的应用程序获取一个数字列表,然后使用网络服务将它们相加,我可以使用 SOAP 成功地做到这一点,但现在我在使用 WCF 尝试时遇到了麻烦.
My application takes a list of numbers then sums them using a webservice, I can successfuly do this using SOAP but now I am running into trouble trying it with WCF.
Webservices09004961.ServiceReference1.Service1SoapClient SumCLient = new ServiceReference1.Service1SoapClient();
Webservices09004961.ServiceReference2.IService1 SumClientWCF = new ServiceReference2.Service1Client();
请注意,我调用客户端方法的方式与这似乎没问题.
Notice that I call the client method the same way this seems fine.
但是,当我尝试相同的方法时,我似乎无法像以前使用肥皂的方法那样调用 ArrayOfDoubles:
However when I try the same method I cannot seem to call ArrayOfDoubles like my previous method using soap:
Webservices09004961.ServiceReference2.Service1Client arrayOfdoubles = new ServiceReference2.Service1Client(); //this line is wrong but I tryed it anyway
//Webservices09004961.ServiceReference1.ArrayOfDouble arrayOfDoubles = new Webservices09004961.ServiceReference1.ArrayOfDouble();
arrayOfDoubles.AddRange(myArrai12);
string f = SumCLientWCF.CalculateSum(arrayOfDoubles);
Console.WriteLine("The sum total equals: " + f);
我担心的问题在于我的 wcf 方法,Service1.svc.cs 看起来像这样:
My problem I fear lies in my wcf method, Service1.svc.cs looks like this:
namespace WcfSum
{
// 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 string CalculateSum(List<double> listDouble)
{
return listDouble.Sum().ToString();
//return listDouble.Select(n => (double)n).ToString();
}
}
}
我觉得这样好吗?我的 IService 可能是问题,这就是我所拥有的:
This seems fine to me? My IService tho may be the problem this is all I have for it:
namespace WcfSum
{
// 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 CalculateSum(List<double> listDouble);
}
通常,一旦我输入 Myservice.ServiceReference1,我就会期待.arrayofdoubles
会出现,但这次我没有那个选项,我得到的唯一选项是 Service1
或 serviceclient
.
Normally I would expect once I type Myservice.ServiceReference1. arrayofdoubles
would come up but I dont have that option this time the only option I am getting is Service1
or serviceclient
.
编辑
为了澄清一点,因为我使用这种方法(因为 ArrayOfDoubles 不像我的肥皂版本那样注释掉)
To clarifify abit more because I use this method (because ArrayOfDoubles isnt there like with my soap version commented out)
Webservices09004961.ServiceReference2.Service1Client arrayOfdoubles = new ServiceReference2.Service1Client(); //this line is wrong but I tryed it anyway
//Webservices09004961.ServiceReference1.ArrayOfDouble arrayOfDoubles = new Webservices09004961.ServiceReference1.ArrayOfDouble();
我收到错误消息:
Error 1 'Webservices09004961.ServiceReference2.Service1Client' does not contain a definition for 'AddRange' and no extension method 'AddRange' accepting a first argument of type 'Webservices09004961.ServiceReference2.Service1Client' could be found (are you missing a using directive or an assembly reference?)
在 AddRange 下的这一行.
On this line under AddRange.
arrayOfdoubles.AddRange(myArrai12);
我正在努力找出原因:
Webservices09004961.ServiceReference2.
不会像我的soap 版本那样显示ArrayOfDoubles
.
Webservices09004961.ServiceReference2.
wont show ArrayOfDoubles
Like it does with my soap version.
这可能有助于显示正在发生的事情:
This might help show whats going on:
推荐答案
好的,一些修复:
var arrayOfdoubles = new ServiceReference2.Service1Client();
var inputData = new List<double> { 1.1, 2.2 };
string f = arrayOfdoubles.CalculateSum(inputData);
Console.WriteLine("The sum total equals: " + f);
显然 arrayOfdoubles
不是一个很好的名字(它是客户端代理),但我把它作为对你的代码的引用.
Obviously arrayOfdoubles
is not a very good name (it's the client proxy) but I left it as a reference to your code.
这篇关于WCF 双打数组未成功调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!