Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 以对象为参数的Web服务_.net_Vb.net_Linq_Web Services_Wcf - Fatal编程技术网

.net 以对象为参数的Web服务

.net 以对象为参数的Web服务,.net,vb.net,linq,web-services,wcf,.net,Vb.net,Linq,Web Services,Wcf,基本上 我有一个客户端控制台,使用我定义的名为“Part”的类。这门课在一个共享的图书馆里举行 <Serializable()> _ Public Class Part() Public Property Success As Boolean = False Public Property ExportID As Integer = 0 end class 但是,当我尝试在客户端调用此方法时,它总是出错,并告诉我SharedCl

基本上

我有一个客户端控制台,使用我定义的名为“Part”的类。这门课在一个共享的图书馆里举行

    <Serializable()> _
    Public Class Part() 
       Public Property Success As Boolean = False
       Public Property ExportID As Integer = 0
    end class
但是,当我尝试在客户端调用此方法时,它总是出错,并告诉我SharedClass.Part类型的对象无法转换为WebSerivce.Part

    <WebMethod()>
    Public Function AddPart(Byval objPart as Part) As Boolean

    End Function

作为布尔值的公共函数AddPart(Byval objPart作为Part)
端函数

我99%肯定我错过了某一步,但就我的一生而言,我无法做到这一点。上面的代码是为说明而编写的,因此可能是错误的。

对于WCF,请确保您正在用“DataContract”装饰“Part”类&它的属性带有“DataMember”属性。对于Web服务,我认为您不需要做任何额外的事情

这是一个示例Web服务

using System.Web.Services;

namespace WebServiceWithJson
{
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class SayHelloService 
    {
        [WebMethod]
        public string GreetingsWithObj(SayHelloDto ObjSayHelloDto)
        {
            return ObjSayHelloDto.Greeting + " " + ObjSayHelloDto.Name;
        }
    }
    public class SayHelloDto
    {
        public string Greeting { get; set; }
        public string Name { get; set; }
    }
}
添加引用,这就是您可以使用的方式

using System;
using SayHelloSvcConsumer.SayHelloServiceReference;
namespace SayHelloSvcConsumer
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var ObjSayHelloService = new SayHelloServiceSoapClient();
            var ObjSayHelloDto = new SayHelloDto
                {
                    Greeting = "Hello",
                    Name = "Rasmita"
                };
            var GreetingMsg = ObjSayHelloService.GreetingsWithObj(ObjSayHelloDto);
            Response.Write(GreetingMsg);
        }
    }
}
如果你能发布任何服务的示例代码,那就更好了。 希望能有所帮助

using System;
using SayHelloSvcConsumer.SayHelloServiceReference;
namespace SayHelloSvcConsumer
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var ObjSayHelloService = new SayHelloServiceSoapClient();
            var ObjSayHelloDto = new SayHelloDto
                {
                    Greeting = "Hello",
                    Name = "Rasmita"
                };
            var GreetingMsg = ObjSayHelloService.GreetingsWithObj(ObjSayHelloDto);
            Response.Write(GreetingMsg);
        }
    }
}