WCF 契约相关...

春风十里耶耶耶 2012-04-27 11:55:33


[DataContract(Name = "LinkItem_Contract", Namespace = "http://schemas.thatindigogirl.com/samples/2006/06")]
public class LinkItem
{

private long m_id;
private string m_title;
private string m_description;
private DateTime m_dateStart;
private DateTime m_dateEnd;
private string m_url;

[DataMember(Name = "Id_Contract", IsRequired = false, Order = 0)]
public long Id
{
get { return m_id; }
set { m_id = value; }
}

[DataMember(Name = "Title_Contract", IsRequired = true, Order = 1)]
public string Title
{
get { return m_title; }
set { m_title = value; }
}
}

///调用

LinkItem_Contract item = new LinkItem_Contract();

item.Id_Contract = int.Parse(this.txtId.Text);
item.Title_Contract = this.txtTitle.Text;


看到别人的例子中,有上面的用法,我想使用这种方式调用方法,但是提示报错的,怎么解决...
...全文
88 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 的回复:]
那你这个差得太远了,根本没有办法编译。属于把驴唇的代码贴在马脸的代码中了。
[/Quote]

刚刚吃饭去了,有些着急,一会整理下思路,再说下,希望继续关注...
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]
引用 2 楼 的回复:
你压根没在用WCF的方法,只是用到了一个远程对象而已。


是这样的,clint客户端为windows应用程序。


C# code


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using Sys……
[/Quote]
在Service References文件夹中,存放localhost.map,map文件下面包含localhost.cs。

在client客户端,也就是GigEntry中,引用using GigEntry.localhost;
就可以引用LinkItem_Contract item = new LinkItem_Contract();

把这个using GigEntry.localhost 注释,同样提示LinkItem_Contract 找不到类型或命名空间..
threenewbee 2012-04-27
  • 打赏
  • 举报
回复
那你这个差得太远了,根本没有办法编译。属于把驴唇的代码贴在马脸的代码中了。
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]
你压根没在用WCF的方法,只是用到了一个远程对象而已。
[/Quote]

是这样的,clint客户端为windows应用程序。


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using GigEntry.localhost;


namespace GigEntry
{
public partial class GigInfoForm : Form
{
public GigInfoForm()
{
InitializeComponent();
}

localhost.GigManagerServiceContractClient m_proxy = new GigEntry.localhost.GigManagerServiceContractClient();

private void cmdSave_Click(object sender, EventArgs e)
{
LinkItem_Contract item = new LinkItem_Contract();

item.Id_Contract = int.Parse(this.txtId.Text);
item.Title_Contract = this.txtTitle.Text;
item.Description_Contract = this.txtDescription.Text;
item.DateStart_Contract = this.dtpStart.Value;
item.DateEnd_Contract = this.dtpEnd.Value;
item.Url_Contract = this.txtUrl.Text;

m_proxy.SaveGig(item);
}
}}

在client客户端中,有个map文件

<?xml version="1.0" encoding="utf-8"?>
<ServiceReference>
<ProxyGenerationParameters
ServiceReferenceUri="http://localhost:8000/"
Name="localhost"
NotifyPropertyChange="True"
UseObservableCollection="False">
</ProxyGenerationParameters>
<EndPoints>
<EndPoint
Address="net.tcp://localhost:9000/GigManagerService"
BindingConfiguration="NetTcpBinding_GigManagerServiceContract"
Contract="GigEntry.localhost.GigManagerServiceContract"
>
</EndPoint>
</EndPoints>
</ServiceReference>

  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
晕,报什么错也没说。
[/Quote]
找不到类型或命名空间...
qldsrx 2012-04-27
  • 打赏
  • 举报
回复
你压根没在用WCF的方法,只是用到了一个远程对象而已。
threenewbee 2012-04-27
  • 打赏
  • 举报
回复
晕,报什么错也没说。

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧