- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
在我的 Web 项目中,我有一个包含 REST 服务的 TestStreamingService.svc 文件。
服务契约(Contract):
[ServiceContract(Namespace = "")]
public interface ITestStreamingService
{
[OperationContract]
[WebGet(UriTemplate = "Download?file={file}&size={size}")] //file irrelevant, size = returned size of the download
Stream Download(string file, long size);
[OperationContract]
[WebInvoke(UriTemplate= "Upload?file={file}&size={size}", Method = "POST")]
void Upload(string file, long size, Stream fileContent);
[OperationContract(AsyncPattern=true)]
[WebInvoke(UriTemplate = "BeginAsyncUpload?file={file}", Method = "POST")]
IAsyncResult BeginAsyncUpload(string file, Stream data, AsyncCallback callback, object asyncState);
void EndAsyncUpload(IAsyncResult ar);
}
服务实现(*.svc 文件)
使用系统;使用 System.IO;使用系统服务模型;使用 System.ServiceModel.Activation;使用 ICode.SHF.Tests;
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)][服务行为(InstanceContextMode=InstanceContextMode.Single)]公共(public)类 TestStreamingService : ITestStreamingService{
public Stream Download(string file, long size)
{
return new SHFTestStream(size);
}
public void Upload(string file, long size, Stream fileContent)
{
FileInfo f = new FileInfo(String.Format(@"C:\{0}", file));
using (FileStream fs = f.Create())
{
CopyStream(fileContent, fs);
fs.Flush();
fs.Close();
}
}
public IAsyncResult BeginAsyncUpload(string file, Stream data, AsyncCallback callback, object asyncState)
{
return new CompletedAsyncResult<Stream>(data, file);
}
public void EndAsyncUpload(IAsyncResult ar)
{
Stream data = ((CompletedAsyncResult<Stream>)ar).Data;
string file = ((CompletedAsyncResult<Stream>)ar).File;
StreamToFile(data, file);
}
private void StreamToFile(Stream data, string file)
{
string subDir = Guid.NewGuid().ToString("N");
string uploadDir = Path.Combine(Path.GetDirectoryName(typeof(TestStreamingService).Assembly.Location), subDir);
Directory.CreateDirectory(uploadDir);
byte[] buff = new byte[0x10000];
using (FileStream fs = new FileStream(Path.Combine(uploadDir, file), FileMode.Create))
{
int bytesRead = data.Read(buff, 0, buff.Length);
while (bytesRead > 0)
{
fs.Write(buff, 0, bytesRead);
bytesRead = data.Read(buff, 0, buff.Length);
}
}
}
公共(public)类 CompletedAsyncResult : IAsyncResult{ T数据;
string file;
public CompletedAsyncResult(T data, string file)
{ this.data = data; this.file = file; }
public T Data
{ get { return data; } }
public string File
{ get { return file; } }
#region IAsyncResult Members
public object AsyncState
{
get { return (object)data; }
}
public System.Threading.WaitHandle AsyncWaitHandle
{
get { throw new NotImplementedException(); }
}
public bool CompletedSynchronously
{
get { return true; }
}
public bool IsCompleted
{
get { return true; }
}
#endregion
我的 Web.Config
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="REST">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="ICode.SHF.SL.Tests.Web.TestStreamingService.customBinding0"/>
</webHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
/>
<services>
<service name="ICode.SHF.SL.Tests.Web.TestStreamingService">
<host>
<baseAddresses>
<add baseAddress="http://localhost:40000/Streaming"/>
</baseAddresses>
</host>
<endpoint name="TestStreamingEndpoint" address="RESTService" binding="webHttpBinding" bindingConfiguration="ICode.SHF.SL.Tests.Web.TestStreamingService.customBinding0"
contract="ICode.SHF.SL.Tests.Web.ITestStreamingService" behaviorConfiguration="REST"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
</configuration>
(使用 WebClient.OpenWriteAsync(用于上传)和 OpenReadAsync(用于下载))
用于客户端的 uri 是:“http://localhost:40000/Streaming/Service/Download?file=xxx&size=65536”
当我在 IE 中使用以下 uri 时:“http://localhost:40000/TestStreamingService.svc/Download?file=xxx&size=65536”下载操作开始并且下载的文件与传递的大小匹配。
虽然我在 WebClient 中使用 IE uri 没有成功。
任何人都可以向我解释我做错了什么吗?看来我错过了一些基本的东西......
最佳答案
您的网站是否需要身份验证?至于 fiddler ,请尝试将您的网络客户端连接到:
http://localhost.:40000/Streaming/Service/Download?file=xxx&size=65536
(注意 localhost
之后的额外点)
关于c# - 从 Silverlight 使用 REST 服务时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4759854/
我正在尝试从 F# 编译代码以在 Silverlight 中使用。我编译: --noframework --cliroot "C:\program Files\Microsoft Silverligh
我正在为 Silverlight 安装一个编程环境并试图理顺需要安装的内容,感谢反馈: 在 http://silverlight.net/GetStarted ,第一点允许您安装“ Silverlig
Silverlight RIA 值得学习还是我应该坚持普通的 Silverlight? 背景: 我在 WPF 中做了几个小应用程序 我有 12 年的 VB6/WinForms 模型商业应用经验 我希望
我已经熟悉 Silverlight 编程,但没有任何 GIS 经验。 我作为 Silverlight 开发人员的角色只是显示现有的 GIS 数据。 如果你们有任何经验arcGIS silverligh
我需要在我的 Silverlight 应用程序中创建滚动选取框。选取框需要从右向左滚动。当它完成滚动时,它需要自动重新启动 诀窍是,我需要使用 ItemsControl,因为项目将在滚动时添加到列表中
Silverlight 导航模板在浏览器外运行时是否有效? 最佳答案 当然可以。 并且您可以使用 NavigationServices 函数来创建自定义的“后退”或“前进”按钮 很好的例子:Link
用户通过导航到给定的 URL 在他们的浏览器中启动 Silverlight 应用程序。 然后用户打开另一个浏览器并通过导航到相同的 URL 启动相同的 Silverlight 应用程序。 应用程序的第
Silverlight 4 程序集二进制文件是否与 Silverlight 5 兼容。SL4 程序集是否“在 SL5 运行时中运行”?如果兼容,是否100%兼容。您应该能够在您的 SL5 项目中使用第
很难说出这里问的是什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或言辞激烈,无法以目前的形式合理回答。如需帮助澄清此问题以便可以重新打开,visit the help center . 9年前关闭
我正在寻找是否可以在可以在 application.resources 中设置然后在整个应用程序中使用的 Silverlight 控件中使用应用程序范围的字体。他们不需要指定有关字体的其他内容,例如粗
我正在使用Silverlight4。我想用一个可用字体列表填充组合框。我搜索过很多东西,找不到解决方法。似乎有很多死胡同。五月份曾提出过类似的问题,但没有合适的答案。 当然不是不可能吗? 最佳答案 如
我正在为 Silverlight 很好地实现弱事件模式以避免内存泄漏。 似乎有一些实现,但代码并非微不足道,很难知道哪个是正确的。我找不到微软的任何官方推荐。 如果可能的话,我追求简单的语法。 干杯。
Silverlight 应用程序是在您每次访问该站点时都会下载,还是会检查版本/大小信息并仅下载较新版本的文件? 最佳答案 Silverlight 2 在这方面没有什么特别的,我读过的最简洁的解释来自
我正在尝试在 silverlight 中使用样式触发器,如下所示:
我想尝试制作一个包含多个 Silverlight 画廊中的图片的 asp 网站。我想这样做的原因是我想要这样的东西: Text describing some places. Gallery with
WPF 3.5 有 PresentationTraceSources用于诊断和WPFPerf用于性能和数据绑定(bind)诊断。 Silverlight 是否有等效的工具/库? 最佳答案 尽管我已将
我有一个表示有向图的数据结构,我正在寻找一个好的 Silverlight 可视化,以允许我从一个节点导航到另一个节点,最好有一些漂亮的动画。 有没有人知道这种显示的任何好的 UI 控件或框架?甚至来自
我可以将byte []转换为图像: byte[] myByteArray = ...; // ByteArray to be converted MemoryStream ms = new Memo
我有多个Silverlight项目,希望使用相同的样式,配色方案和一些模板化对象。 我该如何完成? 最佳答案 一种实现方法是创建一个新的silverlight类库,该库将是您共享的主题/样式程序集,其
我正在尝试使用 SLLAUNCHER.EXE 启动已安装的 SL Out-of-Browser App。运行以下命令后,桌面上的 MyApp 启动图标就消失了。如果我在没有覆盖开关的情况下尝试它,则不
我是一名优秀的程序员,十分优秀!