小编Raj*_*mar的帖子

如何在不显示结果的情况下执行SQL查询

是否可以在不显示结果的情况下执行SQL查询?

喜欢

Select * from Table_Name
Run Code Online (Sandbox Code Playgroud)

运行此查询后,结果不应该显示在sql server中.

sql sql-server

39
推荐指数
6
解决办法
8万
查看次数

我可以一起使用DataContract和Serializable吗?

我正在研究WCF服务.我的所有类都已使用[Serializable]属性进行序列化,但由于"k__BackingField"属性命名问题,我使用了DataContract和DataMember属性.我可以同时使用这两个属性,如下所示:

[Serializable]
[DataContract]
public class User
{

  [DataMember]
  public string Name { get; set; }

  [DataMember]
  public int UserID { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

它是否正确?

我也有类似的解决方案. C#自动对JSON进行反序列化

Serializable和DataContract(不是?)

wcf datacontract serializable

25
推荐指数
1
解决办法
2万
查看次数

如何使用webinvoke方法(Post或PUT)在wcf rest中传递多个body参数

我在WCF中编写了一个REST服务,我在其中创建了一个方法(PUT)来更新用户.对于这种方法,我需要传递多个身体参数

[WebInvoke(Method = "PUT", UriTemplate = "users/user",BodyStyle=WebMessageBodyStyle.WrappedRequest)]
[OperationContract]
public bool UpdateUserAccount(User user,int friendUserID)
{
    //do something
    return restult;
}
Run Code Online (Sandbox Code Playgroud)

虽然如果只有一个参数,我可以传递用户类的XML实体.如下:

var myRequest = (HttpWebRequest)WebRequest.Create(serviceUrl);
myRequest.Method = "PUT";
myRequest.ContentType = "application/xml";
byte[] data = Encoding.UTF8.GetBytes(postData);
myRequest.ContentLength = data.Length;
//add the data to be posted in the request stream
var requestStream = myRequest.GetRequestStream();
requestStream.Write(data, 0, data.Length);
requestStream.Close();
Run Code Online (Sandbox Code Playgroud)

但是如何传递另一个参数(friendUserID)值?谁能帮我?

wcf webinvoke parameter-passing

8
推荐指数
1
解决办法
2万
查看次数

WCF中的HttpContext

我在WCF中编写了一个简单的REST API,并且身份验证机制使用API​​密钥.一旦客户端在请求头中提交API密钥,我在服务器端(在覆盖RequestInterceptor类的ProcessRequest()方法的BaseService类中)检查它,如下所示:

public partial class BaseService : RequestInterceptor
{
    public BaseService() : base(false) { }

    #region Process Request
    public override void ProcessRequest(ref RequestContext requestContext)
    {
        if (IsValidApiKey(requestContext))
           //put some values in HttpContext object.

     }
Run Code Online (Sandbox Code Playgroud)

...

现在我在我的REST服务中启用了aspnet兼容性,但我仍然无法在上面的ProcessRequest覆盖中访问HttpContext对象. 请注意,可以从服务方法内部访问HttpContext,但不能在ProcessRequest方法中访问.

有什么想法吗?

rest wcf httpcontext

7
推荐指数
1
解决办法
1916
查看次数

WCF中URI模板中的附加/可选查询字符串参数

我在WCF中编写了一个简单的REST服务,其中我使用相同的URI模板但使用不同的方法(POST和GET)创建了2个方法.对于GET方法,我还发送其他查询参数,如下所示:

    [WebInvoke(Method = "POST", UriTemplate = "users")]
    [OperationContract]
    public bool CreateUserAccount(User user)
    {
        //do something
        return restult;
    }

    [WebGet(UriTemplate = "users?userid={userid}&username={userName}")]
    [OperationContract]
    public User GetUser(int userid, string userName)
    {
       // if User ID then 
       //   Get User By UserID
       //else if User Name then 
       //   Get User By User Name
       //if no paramter then do something

    }
Run Code Online (Sandbox Code Playgroud)

当我用方法POST调用CreateUserAccount它工作正常但是当我使用GET调用GetUser方法并且只发送一个查询字符串参数(userID或UserName)时,它给出了错误"HTTP方法不允许",但是如果发送两个参数,那么它就是好的.

谁能帮我?

c# wcf

4
推荐指数
1
解决办法
7923
查看次数