首先抱歉提出这样一个愚蠢的问题,我是asp.net中的新手.
所以,我应该定期做一些事情,说我是网站heartpatients.com的所有者(假设),我希望我的每个网站用户访问该网站,2小时后显示一条消息"拿你的药".所以,基本上这都是我的问题,我应该在每2小时(或4,6之后的任何时间)之后显示此消息,我也可以如何自定义时间.
还有一件事,比如我在WCF服务中有这个方法,它显示了这条消息,如何在特定时间调用该服务,甚至用户配置(比如有人在10小时后吃药?)那么如何在用户指定的时间后定期传递该服务(服务中的特定方法)?
我希望我的问题很清楚.
任何帮助表示赞赏.
我正在使用这些方法运行WCF服务,
public string UploadInspections(Inspection[] inspections)
public string UploadInspection(Inspection inspection)
[DataContract]
public partial class Inspection
{
[DataMember]
public DateTime DateTime { get; set; }
[DataMember]
public int Id { get; set; }
[DataMember]
public string Comment { get; set; }
[DataMember]
public int Rating { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
从javascript我尝试使用JSON调用这些方法的POST.我用于UploadInspection方法的JSON是这样的,
{"Id":10,"Comment":"New One","Rating":3}
Run Code Online (Sandbox Code Playgroud)
调用了UploadInspection方法,但检查对象设置为null.
我不知道如何使用JSON指定Date字段,我想也许解析器不喜欢没有Date字段的JSON.我从Inspection对象中删除了Date字段,但同样的事情发生了.
另外,对于作为数组的UploadInspections方法,JSON应该是什么样的?我试过一些JSON,
"inspections": [{"Id":10,"Comment":"New One","Rating":3}]
Run Code Online (Sandbox Code Playgroud)
还有这个,
[{"Id":10,"Comment":"New One","Rating":3}, {"Id":11,"Comment":"New Two","Rating":2}]
Run Code Online (Sandbox Code Playgroud)
但我得到了这个错误,
OperationFormatter encountered an invalid Message body. Expected to find an attribute with name 'type' and value 'object'. …Run Code Online (Sandbox Code Playgroud) 我想保护一个简单的WCF服务,从客户端发送用户名和密码,并使用CustomUserNamePasswordValidator.对于我在Web上尝试的每个例子,我都被困在巨大的配置和模糊的错误,SSL,证书等...
最相似的替代方法(让你更好地理解)是将"serviceUsername"和"servicePassword"参数(可能是散列)传递给服务的每个方法并在此处执行身份验证,但我承认这是一个丑陋和肮脏的解决方案.
我不介意加密凭证,因为它不是一个安全关键服务.我只需要一种基本的保护形式.
谢谢!
亚历山德罗
我有WCF服务.这是配置
<basicHttpBinding>
<binding name="EmergencyRegistratorBinding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
Run Code Online (Sandbox Code Playgroud)
和服务配置
<service behaviorConfiguration="Default" name="Breeze.AppServer.Emergencies.EmergencyRegistrator">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="EmergencyRegistratorBinding"
contract="Services.IEmergencyRegistrator" />
</service>
Run Code Online (Sandbox Code Playgroud)
一切都很好.但我需要将basicHttpBingind更改为DuplexBinding.我添加了延伸:
<extensions>
<bindingElementExtensions>
<add name="pollingDuplex" type="System.ServiceModel.Configuration.PollingDuplexElement, System.ServiceModel.PollingDuplex"/>
</bindingElementExtensions>
</extensions>
Run Code Online (Sandbox Code Playgroud)
并改变上面提到的行:
<customBinding>
<binding name="DuplexmergencyRegistratorBinding">
<binaryMessageEncoding/>
<pollingDuplex maxPendingSessions="2147483647" maxPendingMessagesPerSession="2147483647" inactivityTimeout="02:00:00" serverPollTimeout="00:05:00"/>
<httpTransport authenticationScheme="Negotiate"/>
</binding>
</customBinding>
Run Code Online (Sandbox Code Playgroud)
和
<service behaviorConfiguration="Default" name="Breeze.AppServer.Emergencies.EmergencyRegistrator">
<endpoint address="" binding="customBinding" bindingConfiguration="DuplexmergencyRegistratorBinding" contract="Breeze.Core.Services.IEmergencyRegistrator" />
<endpoint address="mex" binding="customBinding" bindingConfiguration="DuplexmergencyRegistratorBinding" contract="IMetadataExchange"/>
</service>
Run Code Online (Sandbox Code Playgroud)
我已将服务参考添加到WCF项目.引用已成功添加,但Reference.cs几乎为空.
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.225
//
// Changes …Run Code Online (Sandbox Code Playgroud) 我需要在开发和部署期间在http和https之间切换.
为此,我需要在web.config中进行以下更改:
<behaviors>
<serviceBehaviors>
<behavior name="DirectInstallHelperServiceBehavior">
<!-- need to change to <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true"> -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="false">
</serviceMetadata>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding>
<!-- need to add the following, but don't know how
<security mode="Transport">
<transport clientCredentialType="Basic"/>
</security>
-->
</binding>
</webHttpBinding>
</bindings>
Run Code Online (Sandbox Code Playgroud)
所以我尝试在Web.Release.config中添加以下行:
<behaviors>
<serviceBehaviors>
<behavior name="DirectInstallHelperServiceBehavior">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" xdt:Transform="setAttribute(httpsGetEnabled, httpGetEnabled)" xdt:Locator="Match(name)"></serviceMetadata>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding>
<security mode="Transport" xdt:Transform="InsertAfter(/configuration/system.serviceModel/bindings/webHttpBinding/binding)">
<transport clientCredentialType="Basic"/>
</security>
</binding>
</webHttpBinding>
</bindings>
Run Code Online (Sandbox Code Playgroud)
但我做错了,因为当我将服务发布到我的文件系统时,我仍然看到web.config的开发http版本.任何帮助表示赞赏.
我试图从Web服务获取列表的总和.
[WebMethod]
public string CalculateSum(List<int> listInt)
{
int[] sum = listInt.ToArray();
return sum; // error under sum on this line
}
Run Code Online (Sandbox Code Playgroud)
但我得到的错误无法将int转换为字符串,这应该有用吗?
客户代码:
public partial class Form1 : Form
{
List<int> listInt = new List<int>();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
listInt.Add(Convert.ToInt32(textBox1.Text));
textBox1.Clear();
listBox1.Items.Clear();
for (int i = 0; i < listInt.Count; i++)
{
listBox1.Items.Add(listInt[i]);
}
}
private …Run Code Online (Sandbox Code Playgroud) 我正在尝试研究WCF Web服务,但我对协议ABC(地址,绑定和合同)有点困惑.我知道每一个是什么,但我看不出它和协议WSDL之间的区别.对我来说,两者都是一样的.
有什么区别?
真的感谢
我正在尝试编写一个函数,它将从单个表中返回所有可用的汽车Cars.Carshas carId(int),carManufacturer(varchar),carModel(varchar)和carTaken(bool).
但是我在确定函数应该GetAvailableCars()返回什么数据类型时遇到问题.
我想以carTaken == false格式化的方式将所有可出租的汽车()放在web-client的简单页面上的textArea中.我虽然string[]是个不错的选择.
public string[] GetAllAvailableCars()
{
var result =
from car in carsDB.Cars
where (car.carTaken == false)
select car;
return result;
}
Run Code Online (Sandbox Code Playgroud) 使用绝对文件名(例如C:/tinkiwinki/dipsy.lala)使用System.Drawing.Image.Save(Stream, ImageCodecInfo, EncoderParameters)IIS中托管的WCF服务中的方法在服务器中保存图像时,它不会保存图像,甚至不会抛出异常.
我们有一个帮助器类,它有一个SaveJpeg方法:
public class Tools
{
public static void SaveJpeg(string path, Image img, int quality)
{
if (quality < 0 || quality > 100)
throw new ArgumentOutOfRangeException("Quality must be between 0 and 100.");
EncoderParameter qualityParam =
new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality);
ImageCodecInfo jpegCodec = GetEncoderInfo("image/jpeg");
EncoderParameters encoderParams = new EncoderParameters(1);
encoderParams.Param[0] = qualityParam;
img.Save(path, jpegCodec, encoderParams);
}
}
Run Code Online (Sandbox Code Playgroud)
我们在这样的WCF OperationContract方法中使用它:
string destDirectory = ServerDataFilePath.ImagesPath + @"\" + uploadID.ToString();
if …Run Code Online (Sandbox Code Playgroud) 在我的WCF服务合同中,我已经声明了一个返回List的asyn方法,但是当我在我的客户端收到该方法的返回时,我收到一个数组.我的合同如下:
[OperationContract(AsyncPattern = true)]
IAsyncResult BeginGetUsers(Paramusers paramUserParameters, AsyncCallback callback, object state);
List<Users> EndGetUsers(IAsyncResult result);
Run Code Online (Sandbox Code Playgroud)
在我的客户端,我有以下代码:
Task<List<Users>> task = Task<List<Users>>.Factory.FromAsync(_proxy.Proxy.BeginGetUsers, _proxy.Proxy.EndGetUsers, myParameters, null);
List<Users> myUsers = await task;
Run Code Online (Sandbox Code Playgroud)
在客户端中,我在FromAsync方法的第二个参数中收到错误,因为它表示EndGetUsers方法返回一个数组,而不是一个列表.
我尝试使用一组用户并且工作正常,但我想从异步方法接收列表,而不是数组.可能吗?
谢谢.Daimroc.